• Aucun résultat trouvé

JSON MPRI 2.26.2: Web Data Management

N/A
N/A
Protected

Academic year: 2022

Partager "JSON MPRI 2.26.2: Web Data Management"

Copied!
10
0
0

Texte intégral

(1)

JSON

MPRI 2.26.2: Web Data Management

Antoine Amarilli Friday, December 14th

(2)

JSON

Meaning: JavaScript Object Notation

Main goal: Serializationof data {

"firstName": "John", "lastName": "Smith",

"address": {

"streetAddress": "21 2nd Street",

"city": "New York",

"postalCode": "10021-3100"

},

"phoneNumbers": [

{ "type": "home", "number": "212 555-1234" }, { "type": "office", "number": "646 555-4567" }, { "type": "mobile", "number": "123 456-7890" } ],

}

(3)

JSON syntax

Numbers, including floating numbers, scientific notation

Strings, with delimiters

• Whitespace out of strings isignored, unlike XML

• Quotes, backslashes, control characters must be escaped;

for Unicode,\u0042

Array, ordered list of elements separated by commas

• For instance:[0, 1, "a", 2.4]

Object, dictionary of keys (strings) and values

• For instance:{"a": 1, "b": "c"}

• Theorderamong keys isirrelevant

• Duplicate keys arediscouragedbutallowed

Boolean valuestrue,false; special valuenull

(4)

How to parse JSON with jQuery

function request() {

$.ajax({

url: "data.json",

cache: false,

success: function (data) {

$( "#load" ).html( data.load );

$( "#speed" ).html( data.speed );

} });

}

(5)

Main differences with XML

JSON syntax is (mostly) asubset of JavaScript

JSON once deserialized is navigated as anobject whereas XML is navigated with the DOM

JSON does notmixtext and structured data

JSON syntax issimpler: no comments, attribute, namespaces...

JSON is lighter: compare:

{

"a": ["a1", "a2"],

"b": ["b1", "b2"]

}

<r>

<a> <v>a1</v> <v>a2</v> </a>

<b> <v>b1</v> <v>b2</v> </b>

</r>

JSON isless carefullynormalized

Lessbells and whistles: little typing, no XSLT, etc.

(6)

JSON ambiguities

Noversion numberfor JSON

Multiplecompeting specifications

Nicolas Seriot,Parsing JSON is a Minefield http://seriot.ch/parsing_json.php

https://github.com/nst/JSONTestSuite/blob/

master/results/pruned_results.png

(7)

JSON extensions

JSON Schema, inspired by XML Schema, IETF (still a draft)

Binary serialization formats: MessagePack, BSON, etc.

JSON-LD, extension to store Linked Web data, used on schema.org

YAML: extends JSON with several features, e.g., explicit types, user-defined types, anchors and references

Some JSON parsers are permissive and allow, e.g.,comments

(8)

Querying JSON

Directly supportedin XPath 3.1 and XQuery 3.1 (March 2017)

MongoDBis a NoSQL database using JSON that has its own query language

Manyproposals for a JSON query language: for a survey, see, e.g., Bourhis, Reutter, Suárez, Vrgoč.JSON: data model, query

languages and schema specification.

https://arxiv.org/abs/1701.02221

(9)

Processing JSON

In aprogramming language: you canparsethe JSON then manipulate it as an object

On thecommand line, usejq

https://stedolan.github.io/jq/

curl -s'https://api.github.com/repos/stedolan/jq/commits?per_page=5'| jq '[.[] | {

message: .commit.message, name: .commit.committer.name, parents: [.parents[].html_url]

}]'

Also: line-delimited JSON(newline-separated list of JSON objects)

(10)

JSON and XML: Dispassionate assessment

XML has mostlyfailedon the Web (XHTML, AJAX)

Overengineeredecosystem with manydustytechnologies:

XQuery, XLink, XPointer, XInclude, XSL-FO, RDDL...

However, XML is still widely used as anexchange format

JSON does not replace all XML uses, e.g.,mixed content

Still, if your data iseasy to representas JSON and you don’t need fancy tools(schemas, etc.), use JSON

Références

Documents relatifs

There- fore, the main objective of this paper is to formally define an appropriate data model for JSON, identify the key query- ing features provided by the existing JSON systems,

Events from input stream can be filtered using various predicates on it’s inner type or inner data4. New

This section explains how RIF built-in datatypes, predicates and functions are translated into JSON Rules, respectively JavaScript.. In order to preserve the semantics type mapping

This short paper presents, JSON Rules, a JavaScript rule engine running Event-Condition-Action rules triggered by Document-Object-Model Events..

CalcuList (Calculator with List manipulation), is an edu- cational language for teaching functional programming extended with some imperative and side-effect features, which are

For future-proof IoT consumer applications, which rely on dynamic (run-time) service discovery and integration of new data sources and ser- vices, we believe the proposed JSON –

Many kinds of scientific data, including satellite imagery, cli- mate simulations and sensor data, can be represented as coverages, which are essentially mappings from points in

We propose a data model based on JSON-LD, in which semantics are added to Web of Things (WoT) APIs, en- hancing their interoperability and evolvability by the