ci: tests for macOS on Gitlab CI
[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::static
11 import json
12
13 var str = """{
14 "blue": [1, 2],
15 "ocean": "water"
16 }"""
17
18 var json = str.parse_json
19
20 # Print json object
21 print json.to_json
22 print json.class_name
23 if not json isa JsonObject then return
24
25 # Print json array
26 var arr = json["blue"]
27 print arr.to_json
28 print arr.class_name
29
30 # edit the object
31 json["ocean"] = new JsonArray.from(["fishy", "salty"])
32 print json.to_json
33 print json.to_pretty_json