JSON: Difference between revisions

Content deleted Content added
Added LFE examples
Line 1,016:
<lang javascript>var data = eval('(' + '{ "foo": 1, "bar": [10, "apples"] }' + ')');</lang>
 
=={{header|LFE}}==
 
This example uses the third-party library "Jiffy".
 
===Encoding===
<lang lisp>
(: jiffy encode (list 1 2 3 '"apple" 'true 3.14))
</lang>
 
The result from that can be made a little more legible with the following:
<lang lisp>
(: erlang binary_to_list
(: jiffy encode (list 1 2 3 '"apple" 'true 3.14)))
</lang>
 
===Decoding===
We can run the encoding example in reverse, and get back what we put in above with the following:
<lang lisp>
(: jiffy decode '"[1,2,3,[97,112,112,108,101],true,3.14]")
</lang>
 
Here's a key-value example:
<lang lisp>
(: jiffy decode '"{\"foo\": [1, 2, 3]}")
</lang>
 
===Decoding to Patterns===
We can also extract the key and value using Erlang patterns:
<lang lisp>
(let (((tuple (list (tuple key value)))
(: jiffy decode '"{\"foo\": [1, 2, 3]}")))
(: io format '"~p: ~p~n" (list key value)))
</lang>
 
=={{header|Mathematica}}==