XML provides a way to label information from diverse data sources including structured and semi-structured documents, relational databases, and object repositories. The Extensible Markup Language, XML, is having a profoundly unifying effect on diverse forms of information. For the first time, XML provides an information interchange format that is editable, easily parsed, and capable of representing nearly any kind of structured or semi-structured information. "Quilt: An XML Query Language for Heterogeneous Data Sources", 2000.
Unfortunately, XML is not well suited to data-interchange, much as a wrench is not well-suited to driving nails. It carries a lot of baggage, and it doesn't match the data model of most programming languages. When most programmers saw XML for the first time, they were shocked at how ugly and inefficient it was. It turns out that that first reaction was the correct one. There is another text notation that has all of the advantages of XML, but is much better suited to data-interchange. That notation is JavaScript Object Notation (JSON). JSON is a better data exchange format. XML is a better document exchange format. Use the right tool for the right job. "JSON: The Fat-Free Alternative to XML", 2006.
universal data format, or a
universal hub format, and some hoped that XHTML would finally unify the Web, with XML as the foundation. But XHTML was not well supported by some browsers, and was never widely accepted as a replacement for HTML 4. Instead, the HTML community has moved strongly in the direction of HTML5. Even for data exchange, many JavaScript programmers decided that XML was too difficult to use in JavaScript programs, opting for JSON instead. While XML won the argument that data should be exchanged using text-based formats with the characteristics listed above, we now have three dominant formats: HTML, XML, and JSON. They are frequently used together. Few tools are designed to work equally well with all three formats, but many developers are expected to.
XML, Java, and the future of the Web, which was written to promote XML. JSON was designed as a programming language-independent representation of typical programming language data structures, and in many languages, a simple library call can convert JSON to programming language structures, or programming language structures to JSON. For this kind of data, JSON programming is dramatically simpler than XML programming, except when you need queries, transformations, or schema validation.
date-time
, date
, time
,
etc. JSON Schema is supported by several tools, and was written up
as an IETF draft, but the draft expired in 2011.
As a result, there is no standard way to support schema validation
or validation of these data types in JSON. That makes it difficult
for JSON interfaces to support declarative contracts via schemas.ItemType
to allow support map types.MapType
can be used to specify the type of a function parameter. Here is the signature of a function that uses a map to specify parsing options.map(xs:integer, element(employee))
matches a map if
all the keys in the map are integers and all the values are
employee elements. If a new entry with a different key type or
value type is added, the type of the map changes.map:get($map, $key)
returns the
value associated with a given key.
The function signature for a map is function($key as
xs:anyAtomicValue) as item()*
, and calling a map function
returns the value for that key (thus, $map($key)
is
a synonym for map:get($map, $key)
. If
$map
is bound to the map shown above, the following
expressions are equivalent, they each evaluate to "Tuesday".map:new | Creates a new map: either an empty map, or a map that combines entries from a number of existing maps. Allows a collation to be specified. |
map:entry | Creates a map that contains a
single key/value pair. Useful for creating maps with
map:new |
map:get | Returns the value associated with a key. |
map:keys | Returns the keys found in a map. |
map:contains | Tests whether a supplied map contains an entry for a given key. |
map:remove | Constructs a new map by removing an entry from an existing map. |
map:collation | Returns the URI of a given map's collation. |
fn:deep-equal2 | Determines whether two
sequences are deep-equal to each other; this function extends
fn:deep-equal to support sequences that contain
maps. |
map:new
function is used to create new
maps from existing ones by specifying a sequence of maps. The
newly created map contains every key/value pair that occurs in
one of these maps; if a given key occurs in more than one map,
its value in the newly created map is taken from the last map
that contains a value for this key. The following examples show how map:new
and map:remove
are used to create modified versions of maps.map:new()
returns map{ }
map:new((map:entry(0, "Sunntig"), map:entry(1, "Määntig")))
returns map{0:="Sunntig",1:="Määntig"}
map:new((map{0:="Sunntig"},map{1:="Määntig",2:="Ziischtig"}))
returns map{0:="Sunntig",1:="Määntig",2:="Ziischtig"}
map:new(map{0:="Sunntig",1:="Määntig",2:="Ziischtig"},map{0:="Sunday",2:="Dienstag"))
returns map{0:="Sunday",1:="Määntig",2:="Dienstag"
let $m:=map{"count":=1} return map:new("count":$m("count")+1)
returns map{"count":2}
map:remove(map{0:="Sunntig",1:="Määntig",2:="Ziischtig"}, 1)
returns map{0:="Sunntig",2:="Ziischtig"}
xsl:iterate
to find the highest earning employee in each department, in a single streaming pass of a document containing employee records.parse-JSON
and serialize-JSON
, that
convert between serialized JSON and XSLT
maps. parse-JSON
converts JSON arrays are converted
to maps with integer-valued keys.
parse-json('{"x":1, "y":[3,4,5]}')
returns map{"x":=1e0,"y":=map{1:=3e0,2:=4e0,3:=5e0}}
.let $m := parse-json('{"x":1, "y":[3,4,5]}') return $m("y")(2)
returns 4e0
.ItemType
to support the types of JSON items.JSONItemTest
can be used to declare the type of a function parameter or return.jn:null()
creates a
null value.function($key as
xs:string) as item()?
. An object selector returns the
value associated with a given key, as in the following
example.function(xs:integer) as item()?
. An array selector
returns the value found at a given position, as in the following
example:$s
is a sequence, then $s($param)
is translated to:collection("sales")
contains the following data:collection("products")
contains the following data:collection("stores")
contains the following data:is
,
<<=
, >>
,
union
, intersect
, and
except
operators.integer
, string
,
and boolean
). The type of a map depends on the
types of its keys and values at any given time. In JSONiq, a
key is always a string, as it is in JSON.:=
as a delimiter between name/value pairs,
instead of the :
delimiter used by
JSON.parse-json()
function
converts the JSON text ["a", "b", null]
to the map
map{1:="a", 2:="b", 3:=()}
, and does not support
arrays in XPath per se. If a transformation creates a new copy of
the map, removing one of the entries, the positions of the other
entries are not adjusted; for example, consider the following
expression:$a(1)
), not the subscript
operator (e.g. $a[1]
). Functions, operators, and
expressions that operate on sequences all treat an array as a
single item. For instance, the following expression returns a
single item:[1, 2,
3]
, not the sequence 1, 2, 3
. JSONiq provides
the members()
function to convert an array to a
sequence:1, 2,
3
.[1, 2][1]
is
not equivalent to the expression [1, 2](1)
. The array
selector (1)
returns the first member of the
sequence, which is 1
. The positional predicate
[1]
returns the first item of the sequence. In XPath,
an item is identical to a singleton sequence containing that item,
so [1, 2][1]
is equivalent to ([1,
2])[1]
, which returns the first item in the sequence:
[1, 2]
.XML vs the Web, James Clark. [online] http://blog.jclark.com/2010/11/xml-vs-web_24.html
Deprecating XML, Norman Walsh. [online] http://norman.walsh.name/2010/11/17/deprecatingXML
JSON and XML, Tim Bray. [online] http://www.tbray.org/ongoing/When/200x/2006/12/21/JSON
Mongo Query Language: Advanced Queries.[online] http://www.mongodb.org/display/DOCS/Advanced+Queries.
Data Types and Conventions, http://www.mongodb.org/display/DOCS/Data+Types+and+Conventions.
BSON, http://www.mongodb.org/display/DOCS/BSON.
UnQL: Unstructured Query Language.[online] http://www.unqlspec.org/display/UnQL/Home.
HQL Tutorial, [online] http://dev.wavemaker.com/wiki/bin/Dev/HqlTutorial
Yahoo Query Language, [online] http://developer.yahoo.com/yql/
Hive Language Manual.[online] https://cwiki.apache.org/confluence/display/Hive/LanguageManual
Apache Hadoop: Pig Documentation.[online] http://pig.apache.org/docs/r0.7.0/index.html
Jaql: A Scripting Language for Large Scale Semistructured Data Analysis.[online] http://www.mpi-inf.mpg.de/~rgemulla/publications/beyer11jaql.pdf
A JSON Media Type for Describing the Structure and Meaning of JSON Documents.IETF Internet-Draft [online] http://tools.ietf.org/html/draft-zyp-json-schema-03
A co-Relational Model of Data for Large Shared Data Banks.ACM Queue, March 2011, volume 9, number 3. http://queue.acm.org/detail.cfm?id=1961297