JSON
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
You are encouraged to solve this task according to the task description, using any language you may know.
Load a JSON string into a data structure. Also create a new data structure and serialize it into JSON. Use objects and arrays, and make sure your JSON is valid (http://www.jsonlint.com/).
JavaScript
Requires JSON library, now present in some browsers. <lang JavaScript>var data = JSON.parse('{ "foo": 1, "bar": [10, "apples"] }')
var sample = { "blue": [1,2], "ocean": "water" }; var json_string = JSON.stringify(sample);</lang>
PHP
<lang php><?php $data = json_decode('{ "foo": 1, "bar": [10, "apples"] }'); // dictionaries will be returned as objects $data2 = json_decode('{ "foo": 1, "bar": [10, "apples"] }', true); // dictionaries will be returned as arrays
$sample = array( "blue" => array(1,2), "ocean" => "water" ); $json_string = json_encode($sample); ?></lang>
Python
<lang Python>import json data = json.loads('{ "foo": 1, "bar": [10, "apples"] }')
sample = { "blue": [1,2], "ocean": "water" } json_string = json.dumps(sample)</lang>