Contains everything required to parse and serialise JSON data.
Sample usage for parsing and accessing JSON:
String getAuthor(String json){ value parsedJson = parse(json); if(is String author = parsedJson.get("author")){ return author; } throw Exception("Invalid JSON data"); }
Or if you're really sure that you should have a String value:
String getAuthor(String json){ value parsedJson = parse(json); return parsedJson.getString("author")){ }
You can iterate Json objects too::
{String*} getModules(String json){ value parsedJson = parse(json); if(is Array modules = parsedJson.get("modules")){ return { for (mod in modules) if(is Object mod, is String name = mod.get("name")) name }; } throw Exception("Invalid JSON data"); }
Sample usage for generating JSON data:
String getJSON(){ value json = Object { "name" -> "Introduction to Ceylon", "authors" -> Array { "Stef Epardaud", "Emmanuel Bernard" } }; return json.string; }
Packages | |
ceylon.json | A JSON parser / serialiser |
Dependencies | ||
ceylon.collection | 1.0.0 |
A JSON parser / serialiser
Values | |
nil | Source Code shared nil nil The singleton that represents the |
Functions | |
parse | Source Code Parses a JSON string into a JSON Object Throws:
By: Stéphane Épardaud |
Classes | |
Array | Source Code shared Array Represents a JSON Array |
NullInstance | Source Code shared abstract NullInstance Represents the type of the |
Object | Source Code shared Object Represents a JSON Object |
Printer | Source Code shared abstract Printer A JSON Printer |
StringPrinter | Source Code shared StringPrinter A JSON Printer that prints to a |
nil | Source Code shared nil The singleton that represents the |
Exceptions | |
InvalidTypeException | Source Code shared InvalidTypeException |