| 1 | import json.cjson |
| 2 | |
| 3 | fn test_object_with_null() { |
| 4 | mut root := cjson.create_object() |
| 5 | root.add_item_to_object('name', cjson.create_string('Andre')) |
| 6 | root.add_item_to_object('age', cjson.create_null()) |
| 7 | assert root.print_unformatted() == '{"name":"Andre","age":null}' |
| 8 | unsafe { cjson.delete(root) } |
| 9 | } |
| 10 | |
| 11 | fn test_creating_complex_json() { |
| 12 | mut root := cjson.create_array() |
| 13 | root.add_item_to_array(cjson.create_string('user')) |
| 14 | mut obj := cjson.create_object() |
| 15 | obj.add_item_to_object('username', cjson.create_string('foo')) |
| 16 | obj.add_item_to_object('password', cjson.create_string('bar')) |
| 17 | root.add_item_to_array(obj) |
| 18 | result := root.print_unformatted() |
| 19 | println(result) |
| 20 | |
| 21 | assert result == '["user",{"username":"foo","password":"bar"}]' |
| 22 | unsafe { cjson.delete(root) } |
| 23 | } |
| 24 | |