-
Notifications
You must be signed in to change notification settings - Fork 2
NestedExample
Glythcing edited this page Sep 17, 2018
·
2 revisions
The following example shows the use of the projections and predicates against nested attributes. Examples of "nested" are:
- A sub document within JSON
- A
Map
inside aMap
- An array of sub documents within JSON
- A collection of
Map
s inside aMap
The following example is somewhat contrived but it should suffice to show:
- You query arrays using either
- A wildcard -
[*]
- which queries any element in the array - An index -
[n]
- which queries the specific element in the array
- A wildcard -
- You query and select nested documents using a
.
delimited path - You project on specific array elements using the element index;
[n]
{
"type": "catalog",
"status": "DRAFT",
"version": 3,
"owner": {
"name": "glytching",
"role": "maintainer"
},
"items": [
{
"name": "tap",
"price": 49.99,
"quantity": 10,
"active": true,
"owner": null,
"since": "2018-09-07"
},
{
"name": "sink",
"price": 99.99,
"quantity": 100,
"active": false,
"owner": null,
"since": "2018-09-02"
}
]
}
Tranquil.parse(json).read(
"type, owner.name, items[0].name as firstItemName, items[1].quantity as secondItemQuantity",
"type = 'catalog' and owner.role is not null and (items[*].name='sink' or items[0].name='tap')"
)
Tranquil will return:
{
"type": "catalog",
"owner.name": "glytching",
"firstItemName": "tap",
"secondItemQuantity": 100
}