compiler: handle multi-iterators
[nit.git] / examples / rosettacode / json_output.nit
1 #!/usr/bin/env nit
2 #
3 # This file is part of NIT ( http://www.nitlanguage.org ).
4 # This program is public domain
5
6 # Task: JSON
7 # SEE: <http://rosettacode.org/wiki/JSON>
8 module json_output
9
10 import json
11
12 var str = """{
13 "blue": [1, 2],
14 "ocean": "water"
15 }"""
16
17 var json = str.parse_json
18
19 # Print json object
20 print json.to_json
21 print json.class_name
22 if not json isa JsonObject then return
23
24 # Print json array
25 var arr = json["blue"]
26 print arr.to_json
27 print arr.class_name
28
29 # edit the object
30 json["ocean"] = new JsonArray.from(["fishy", "salty"])
31 print json.to_json
32 print json.to_pretty_json