JSON Batch Pointer defines a syntax that itself conforms to JavaScript Object Notation (JSON) for identifying multiple values within a JSON document. The goal of JSON batch pointer is to have a competitor to GraphQL queries (not mutations) that:
application/json
content-type, can be parsed/serialized/manipulated using the numerous available JSON libraries, can be embedded in other JSON documents)A valid JSON Batch pointer must be a JSON array. Each item in the array must be either:
If the item is a string, it refers to a key in the root level of the target document. If the target document represents an array, valid string items in the JSON batch pointer represent indexes into the array as well as the "length" key to get the number of items in the target array. In this way, arrays are treated like objects.
{ "foo": "bar" }
["foo"]
{ "foo": "bar" }
["hello", "goodbye", -17]
["0", "2", "length"]
{ "0": "hello", "2": -17, "length": 3 }
If the item is a number, it is only valid if the target document is an array. The number is an index into the array.
["hello", "goodbye", -17]
[0, 2]
{ "0": "hello", "2": -17 }
If the item is an object, it is only valid if the target document is also an object and its keys are intended to match keys in the target document. The values of the item must themselves be JSON batch pointers, with their target documents being the values of the corresponding keys in the item's target document.
{
"foo": 3,
"bar": {
"baz": 2,
"quux": "hello"
},
"a": [
{
"b": 3,
"c": "wow"
},
{
"b": 12,
"c": "something"
}
]
}
[
"foo",
{
"bar": ["baz"],
"a": [
{
"0": ["b"]
}
]
}
]
{
"foo": 3,
"bar": {
"baz": 2
},
"a": {
"0": {
"b": 3
}
}
}
If the item is an array, it is only valid if the target document is also an array. The array should have exactly one item in it, and that item should, itself, be a JSON batch pointer. The intent of this is to retrieve a set of properties from each item as an object in the target document (which should be an array).
[
{
"foo": 3,
"bar": "hi"
},
{
"foo": 4,
"bar": "bye",
"baz": true
}
]
[["foo", "bar"]]
[
{
"foo": 3,
"bar": "hi"
},
{
"foo": 4,
"bar": "bye"
}
]
If a key requested in the target document by the JSON batch pointer does not exist, it is simply left out of the retrieved value. This behavior was chosen to differentiate between an unfound value and, say, a value that was set to null
.
{ "foo": 3 }
["bar"]
{}
{ "foo": { "bar": 3 } }
[{ "foo": ["baz"] }]
{ "foo": {} }
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close