import ballerina/io;function main (string[] args) {
json j1 = "Apple";
io:println(j1);
json j2 = 5.36;
io:println(j2);
json j3 = true;
io:println(j3);
json j4 = false;
io:println(j4);
json j5 = null;
json j6 = {name:"apple", color:"red", price:j2};
io:println(j6);
json j7 = [1, false, null, "foo",
{first:"John", last:"Pala"}];
io:println(j7);
}
JSONJSON is a textual format for representing a collection of values: a simple value (string, number, “true”, “false”, “null”), an array of values, or an object. Ballerina has a single type named `json` that can represent any JSON value. Thus, `json` is a built-in union type in Ballerina which can contain values of type string, float, boolean, an array of any, or a map of any. |
|
import ballerina/io;
|
|
function main (string[] args) {
|
|
json j1 = "Apple";
io:println(j1);
|
JSON string value. |
json j2 = 5.36;
io:println(j2);
|
JSON number value. |
json j3 = true;
io:println(j3);
|
JSON true value. |
json j4 = false;
io:println(j4);
|
JSON false value. |
json j5 = null;
|
JSON null value. |
json j6 = {name:"apple", color:"red", price:j2};
io:println(j6);
|
JSON Objects. |
json j7 = [1, false, null, "foo",
{first:"John", last:"Pala"}];
io:println(j7);
}
|
JSON Arrays. They are arrays of any JSON value. |
$ ballerina run json.bal
Apple
5.36
true
false
{"name":"apple","color":"red","price":5.36}
[1,false,null,"foo",{"first":"John","last":"Pala"}]
|
At the command line, navigate to the directory that contains
the |