JSON: Difference between revisions

Content added Content deleted
(→‎{{header|Perl}}: Perl 6 solution)
(added ocaml)
Line 118:
However, there is an ambiguity with parsing JavaScript object literals by themselves, where it might be mistakenly interpreted as a block, and the key followed by a colon as a label. To avoid this, remember to surround it in parentheses to force it to be interpreted as an expression:
<lang javascript>var data = eval('(' + '{ "foo": 1, "bar": [10, "apples"] }' + ')');</lang>
 
=={{header|OCaml}}==
compile with:
ocamlfind opt -o j.opt j.ml -linkpkg -package json-static -syntax camlp4o
 
<lang ocaml>type json item =
< name "Name": string;
kingdom "Kingdom": string;
phylum "Phylum": string;
class_ "Class": string;
order "Order": string;
family "Family": string;
tribe "Tribe": string
>
 
let str = "
{
\"Name\": \"camel\",
\"Kingdom\": \"Animalia\",
\"Phylum\": \"Chordata\",
\"Class\": \"Mammalia\",
\"Order\": \"Artiodactyla\",
\"Family\": \"Camelidae\",
\"Tribe\": \"Camelini\"
}"
 
let () =
let j = Json_io.json_of_string str in
print_endline (Json_io.string_of_json j);</lang>
 
 
=={{header|Oz}}==