[erlang-questions] Erlang de/serializer and data type validator

Richard O'Keefe ok@REDACTED
Thu Aug 4 01:18:05 CEST 2011


On 3/08/2011, at 9:44 PM, Tim Watson wrote:

> For JSON I
> don't know what you'd use as there isn't really a definitive schema
> language for JSON not a definitive transformation language to describe
> converting JSON to/from XML etc.

I suppose it all depends on what "is" is, and what "definitive" defines.
http://json-schema.org/
Implementations exist for Javascript, Java, PHP, Python, Ruby, and some
others.
The RFC is still only a draft, so I suppose you could say it "isn't" yet.

I find it sufficiently horrifying.  (As opposed to XML Schemas, which
are excessively horrifying.)

Converting JSON to XML is dead simple.

Step 1.  Define a universal JSON-in-XML representation.

	<nil/>
	<false/>
	<true/>
	<number>N</number>
	<string>S</string>
	<array>e1 ... en</array>
	<object>v1 ... vn</object>

where each element of an object has a key="ki" attribute.
(A program that builds a DOM or writes a stream of this sort
from any given JSON value is really quite trivial.)

Step 2.  Use any XML->XML transformation language (such as
XSLT) that you please.  Thanks to the universal mapping,
if the translator accepts its input using SAX or DOM, the
the universal representation need never actually exist.





More information about the erlang-questions mailing list