Source Code

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;
}
By: Stéphane Épardaud
License: Apache Software License
Packages
ceylon.json

A JSON parser / serialiser

Dependencies
ceylon.collection1.0.0

A JSON parser / serialiser

By: Stéphane Épardaud
Values
nilSource Code
shared nil nil

The singleton that represents the null value in JSON`.

Functions
parseSource Code
shared Object parse(String str)

Parses a JSON string into a JSON Object

Throws:
  • Exception

    If the JSON string is invalid

By: Stéphane Épardaud
Classes
ArraySource Code
shared Array

Represents a JSON Array

NullInstanceSource Code
shared abstract NullInstance

Represents the type of the null value in JSON.

ObjectSource Code
shared Object

Represents a JSON Object

PrinterSource Code
shared abstract Printer

A JSON Printer

StringPrinterSource Code

A JSON Printer that prints to a String

nilSource Code
shared nil

The singleton that represents the null value in JSON`.

Exceptions
InvalidTypeExceptionSource Code

Represents the failure of a type conversion.
An instance is typically thrown as a result of trying to get and convert an Object member or Array element which cannot be converted to the requested or implied type.