parent

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

{
  "example1": {"a": 1},
  "example2": {"a": {"b": 1}},
  "example3": {
    "a": [{"b": 1}, {"b": 2}],
    "c": 3
  },
  "example4": [0, 1],
  "example5": {}
}

{
  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`)
}
{
  "example1": {"a": 1},
  "example2": {"b": 1},
  "example3": [{"c": 3, "b": 1}, {"c": 3, "b": 2}],
  "example4": null,
  "example5": null
}