Looks like JavaScript, feels like Ruby, and it is a script language fitting in C programmers.
This project is maintained by Kray-G
JSON means JavaScript Object Notation. Kinx Object is just a JSON object and you can use it easily.
Kinx provides a utility function of JSON.parse()
.
You can use it to parse a JSON string and construct an actual Kinx Object.
Here is an example.
var x = JSON.parse(%{
{
"aaa": 10,
"bbb": 20
}
});
System.println(x); // => {"aaa":10,"bbb":20}
JSON.parse()
can also handle the key without quotation.
var x = JSON.parse(%{
{
aaa: 10,
bbb: 20
}
});
System.println(x); // => {"aaa":10,"bbb":20}
You can use JSON.stringify()
to make it stringify from a JSON object,
and also you can apply toJsonString()
to an object directly.
var x = {
aaa: 10,
bbb: 20
};
System.println(JSON.stringify(x)); // => {"aaa":10,"bbb":20}
The second parameter of JSON.stringify()
is a flag and it is true if using indentation.
var x = {
aaa: 10,
bbb: 20
};
System.println(JSON.stringify(x, true));
// {
// "aaa": 10,
// "bbb": 20
// }
Here is the toJsonString
version.
var x = {
aaa: 10,
bbb: 20
};
System.println(x.toJsonString(true));
// {
// "aaa": 10,
// "bbb": 20
// }
var x = JSON.parse(%{
{
aaa: 10,
bbb: 20
}
});
System.println(x);
{"aaa":10,"bbb":20}
var x = {
aaa: 10,
bbb: 20
};
System.println(JSON.stringify(x));
{"aaa":10,"bbb":20}
var x = {
aaa: 10,
bbb: 20
};
System.println(x.toJsonString(true));
{
"aaa": 10,
"bbb": 20
}