This article is not available in Danish, view it in English
parent
TABLE OF CONTENTS
Retrieve the parent of an entry
Definition
object parent(any $entry)
Returns the first object that is the parent of $entry. If $entry has no ancestor, null is returned.
Parameters
any $entry
Any entry in the data.
Returns
object
The parent of $entry.
Examples
Sample data
{
"example1": {"a": 1},
"example2": {"a": {"b": 1}},
"example3": {
"a": [{"b": 1}, {"b": 2}],
"c": 3
},
"example4": [0, 1],
"example5": {}
}Transformation
{
example1: parent(example1.a),
example2: parent(example2.a.b),
example3: example3.a[*].{ c: parent(@).c, b: b },
// For each element in example3.a, create an object of the given format. Notice the change in scope.
example4: parent([0]),
example5: parent(`null`)
}Result
{
"example1": {"a": 1},
"example2": {"b": 1},
"example3": [{"c": 3, "b": 1}, {"c": 3, "b": 2}],
"example4": null,
"example5": null
}Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article