jmespath / jmespath/jmespath.js
Undocumented `$.` ?
- Dominant language
- JavaScript
- Stars
- 847
- Forks
- 101
- PR merge metrics
- No merged PRs in 30d
Description
I was trying to compose an array of objects, adding a property and kept getting errors, until I randomly tried `$.` and everything worked.
Couldn't find mentions in the docs about `$.` though.
Input:
```json
{
"state": [
{
"text": "one",
"data": [ -1, -2, -3 ]
},
{
"text": "two",
"data": [ 4, 5, 6 ]
}
],
"metadata": {
"title": "something" // <=== static value to use
}
}
```
Output desired:
```json
[
{
"x": "one",
"y": [ -1, -2, -3 ],
"title": "something" // <=== static value outside the arrays
},
{
"x": "two",
"y": [ 4, 5, 6 ],
"title": "something" // <=== static value outside the arrays
}
]
```
Attempts:
state[].{ x: text, y: data, title: metadata.title } => title is null (see below)
state[].{ x: text, y: data, title: `metadata.title` } => syntax error
state[].{ x: text, y: data, title: $metadata.title } => Error referencing undefined variable metadata
state[].{ x: text, y: data, title: $.metadata.title } => ** SUCCESS **
Result when using `state[].{ x: text, y: data, title: metadata.title }`
```json
[
{
"x": "one",
"y": [ -1, -2, -3 ],
"title": null
},
{
"x": "two",
"y": [ 4, 5, 6 ],
"title": null
}
]
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.