• Modules
    • By category
    • By name
    • Most popular
    • Most downloaded
    • Repository
  • Register
  • Log in
  • Help
    • Start using Ceylon Herd
    • Publish your first module
    • Module publishing guidelines
    • All about Ceylon
    • Keyboard Shortcuts

    • s Focus search module bar
      ? Open this information panel
      j Move selection down
      k Move selection up
      enter Open current selection
Module info
Name
FroMage / ceylon.json / 1.2.2
Ceylon JSON Platform Module
Category SDK

The Ceylon SDK

Backends JVM JavaScript
Maven coordinates
Compatible Ceylon release JVM: 1.2.x, 1.3.x (latest)
JavaScript: 1.2.1, 1.2.2, 1.3.x (latest)
Published Mar 11, 2016
Stats Downloads (JVM): 2229
Downloads (JS): 132
Source downloads: 908
Authors Stéphane Épardaud
Tom Bentley
License Apache Software License
Description

Contains everything required to parse and serialise JSON data.

Sample usage for parsing and accessing JSON:

import ceylon.json {
    parse, Object = Object
}

String getAuthor(String json){
    value parsedJson = parse(json);
    "author must be a string"
    assert(is Object parsedJson, is String author = parsedJson["author"]);
    return author;
}

Alternatively, this variation will result in an InvalidTypeException instead of an AssertionError if the input JSON data doesn't have the expected format:

import ceylon.json {
    parse, Object
}

String getAuthor(String json){
    assert(is Object parsedJson = parse(json));
    return parsedJson.getString("author");
}

You can iterate JSON objects too:

import ceylon.json {
    parse, Array, Object
}

{String*} getModules(String json){
    assert(is Object 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:

import ceylon.json {
    Object, Array
}

String getJSON(){
    value json = Object {
        "name" -> "Introduction to Ceylon",
        "authors" -> Array {
            "Stef Epardaud",
            "Emmanuel Bernard"
        }
    };
    return json.string;
}
Dependencies
ceylon.collection/1.2.2 shared
ceylon.language/1.2.2
Usage
  • Import
 import ceylon.json "1.2.2";
Module links Members
Imported By
Home
Code repository
Issue tracker
Browse
Download .car
Download .js
Download source archive
Download module documentation
View API documentation

Ceylon Herd v1.24 Copyright 2012-2023 Red Hat. About