Name |
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
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
|
Usage |
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 |