json

13 views
Skip to first unread message

Andreas Stenius

unread,
Feb 23, 2012, 5:25:32 PM2/23/12
to zotonic-developers
Hi,

What is the easiest way to convert json back to term format?

//Andreas

ll...@writersglen.com

unread,
Feb 23, 2012, 5:47:22 PM2/23/12
to zotonic-d...@googlegroups.com
Hi,

As I recall, Mochiweb has a function for that. But my memory may be faulty.

Best wishes,

LRP

Susan Potter

unread,
Feb 23, 2012, 9:47:55 PM2/23/12
to zotonic-d...@googlegroups.com
Reference: http://doc.erlagner.org/mochiweb/mochijson2.html

mochijson2 module has a decode/1 function with this type signature:

decode(S::iolist()) -> json_term()

see type definitions in the reference documentation above.

HTH,
Susan

--
twitter:@SusanPotter
github:mbbx6spp
linkedin:http://www.linkedin.com/in/susanpotter

Andreas Stenius

unread,
Feb 24, 2012, 4:19:47 AM2/24/12
to zotonic-d...@googlegroups.com
Thank you; that's exactly what I was looking for!

Saved me the search :)

//Andreas

2012/2/24 Susan Potter <m...@susanpotter.net>:

Dmitrii Dimandt

unread,
Feb 24, 2012, 1:23:48 PM2/24/12
to zotonic-d...@googlegroups.com
Note that mochijson2 expects json to be strictly in standard format, with quoted keys. That is, {"key": "value"} is ok, {key: "value"} is not.

Moreover, the structure returned by mochijson2 is quite cumbersome, but you'll get used to it :) (mochijson module returns a simpler structure, but I think it may loose some types in the process)
Reply all
Reply to author
Forward
0 new messages