JSON?

Joe Armstrong (AL/EAB) <>
Tue Nov 15 09:12:39 CET 2005


Re the mapping:

IMHO you might get a nicer mapping if you changed strings to binaries.

If you do this then lists will *always* be real lists if you see what I mean,
and the string/list ambiguity goes away. Most of the data will be held in strings
anyway so representing these as binaries should be better for all aspects of performance.

I'd choose this:

	JSON Obj    = type obj()   = {obj, [{key(), val()}]}
	JSON Array  = type array() = [val()]
	JSON Number = type num()   = int() | float() 
	JSON String = type str()   = bin()
	JSON true false null       = true, false null (atoms)

	With Type val() = obj() | array() | num() | str() | true | false | null

I'd let the parser return an association list (not a dict) - since (probably) the object is small
and it's nice to be able to print it and pattern match it directly.

BTW you should hack the pretty printer to print binaries "prettily"

(( Of course if we had proper dynamic structs in the language, erlang terms would be
JSON objects :-) ))


/Joe
  


> -----Original Message-----
> From: 
> [mailto:]On Behalf Of Jim Larson
> Sent: den 15 november 2005 06:52
> To: 
> Cc: 
> Subject: Re: JSON? 
> 
> 
> In message 
> <> 
> you write:
> >I'll bet someone has implemented JSON
> >(http://www.crockford.com/JSON/index.html) for Erlang, but 
> it is not in
> >the implementation list on the web site.
> >
> >If not, I'd welcome any comments on how to do it in Erlang, otherwise
> >I'm sure to muck it up.
> 
> I've got an implementation; I'll see if I can get my company to
> allow me to release it.
> 
> My library works with the following mapping:
> 
> 	JSON Numbers    <==>     Erlang Numbers
>         JSON Strings    <==>     Erlang Strings (lists of 
> Unicode chars)
>         JSON Arrays     <==>     Erlang Tuples
>         JSON Objects    <==>     Erlang Dicts with String keys
>         JSON bool, null <==>     Erlang Atoms 'true', 'false', 'null'
> 
> (The ambiguity that an Erlang dict is represented as a tuple is not
> a problem, since the first element 'dict' is not a legal value for
> encoding.)
> 
> It all works quite well, especially with Joe's middle man framework.
> The only awkwardness is with the string keys for the decoded objects.
> If the atom table were garbage collected, I'd use real atoms here.
> I'd also rather have Richard O'Keefe's "dictionaries", proposed a
> while back, rather than dicts, but it seems like the best available
> choice for now.
> 
> Jim Larson
> 
> 



More information about the erlang-questions mailing list