|
import "json" for Json
|
|
|
|
System.print(Json.stringify(null)) // expect: null
|
|
System.print(Json.stringify(true)) // expect: true
|
|
System.print(Json.stringify(false)) // expect: false
|
|
System.print(Json.stringify(42)) // expect: 42
|
|
System.print(Json.stringify(3.14)) // expect: 3.14
|
|
System.print(Json.stringify("hello")) // expect: "hello"
|
|
System.print(Json.stringify([1, 2, 3])) // expect: [1,2,3]
|
|
System.print(Json.stringify({"a": 1})) // expect: {"a":1}
|
|
|
|
var obj = {"name": "test", "value": 42}
|
|
var json = Json.stringify(obj)
|
|
System.print(json.contains("\"name\"")) // expect: true
|
|
System.print(json.contains("\"test\"")) // expect: true
|
|
|
|
var nested = {"list": [1, 2], "flag": true}
|
|
var nestedJson = Json.stringify(nested)
|
|
System.print(nestedJson.contains("[1,2]")) // expect: true
|
|
System.print(nestedJson.contains("true")) // expect: true
|
|
|
|
System.print(Json.stringify("line\nbreak")) // expect: "line\nbreak"
|