Content deleted Content added
Add GraphQL example |
|||
Line 141:
$ curl -H "Content-type: application/json" -d '{"query": "{ quote { ticker, price } }" }' 'http://localhost:4000/stocks'
{"data":{"quote":{"ticker":"EXPO", "price":287.5}}}
</syntaxhighlight>
=== JSON Support ===
The language provides support for working with JSON values. The builtin type `json` is defined as the following union: ()|boolean|int|float|decimal|string|json[]|map<json>
<syntaxhighlight>
import ballerina/io;
public function main() returns error {
// Syntax for `json` object values is very similar to the syntax of JSON
json person = {name: "John Doe", age: 25};
// Serialized `json` values conforms to the JSON specification
io:println(person);
// The fields of the `json` value can be accessed as follows
string name = check person.name;
int age = check person.age;
}
</syntaxhighlight>
|