• 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
Ceylon JSON Platform Module
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;
}
Category SDK

The Ceylon SDK

Rating 5.00 (rated by 1 user)
Last Published Aug 21, 2017
Stats Downloads (JVM): 349558
Downloads (JS): 9709
Source downloads: 15798
Module links Home
Code repository
Issue tracker
Imported By
Browse
List of published versions
1.3.3 JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: Unknown (10/0) Published Aug 21, 2017 Browse
View docs
1.3.2 JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: Unknown (10/0) Published Mar 1, 2017 Browse
View docs
1.3.1 JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: 1.2.1, 1.2.2, 1.3.x (latest) Published Nov 21, 2016 Browse
View docs
1.3.0-1 JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: 1.2.1, 1.2.2, 1.3.x (latest) Published Oct 26, 2016 Browse
View docs
1.3.0 JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: 1.2.1, 1.2.2, 1.3.x (latest) Published Sep 15, 2016 Browse
View docs
1.2.2 JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: 1.2.1, 1.2.2, 1.3.x (latest) Published Mar 11, 2016 Browse
View docs
1.2.1 JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: 1.2.1, 1.2.2, 1.3.x (latest) Published Feb 11, 2016 Browse
View docs
1.2.0 JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: 1.2.0 (outdated) Published Oct 28, 2015 Browse
View docs
1.1.0 JVM JavaScript JVM: 1.1.0 (outdated) JavaScript: 1.1.0 (outdated) Published Oct 8, 2014 Browse
View docs
1.0.1 JVM JavaScript JVM: 1.0.0 (outdated) JavaScript: 1.0.0 (outdated) Published Nov 27, 2013 Browse
View docs
1.0.0 JVM JavaScript JVM: 1.0.0 (outdated) JavaScript: 1.0.0 (outdated) Published Nov 11, 2013 Browse
View docs
0.6.1 JVM JavaScript JVM: M6 (outdated) JavaScript: M6 (outdated) Published Sep 24, 2013 Browse
View docs
0.6 JVM JavaScript JVM: M6 (outdated) JavaScript: M6 (outdated) Published Sep 20, 2013 Browse
View docs
0.5 JVM JavaScript JVM: M5 (outdated) JavaScript: M5 (outdated) Published Mar 14, 2013 Browse
View docs
0.4 JVM JVM: M4 (oudated) Published Oct 29, 2012 Browse
View docs
0.3.2 JVM JavaScript JVM: M3.1 (outdated) JavaScript: M3.1 (outdated) Published Aug 3, 2012 Browse
View docs
0.3.1 JVM JVM: M3.1 (outdated) Published Jul 6, 2012 Browse
View docs
FroMage commented Sep 20, 2013

Excellent JSON module if I may say so myself :)

You must be logged in to comment.

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