Skip to content

Undocumented $. ? #99

@dluc

Description

@dluc

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:

{
  "state": [
    {
      "text": "one",
      "data": [ -1, -2, -3 ]
    },
    {
      "text": "two",
      "data": [ 4, 5, 6 ]
    }
  ],
  "metadata": {
    "title": "something"     // <=== static value to use
  }
}

Output desired:

[
  {
    "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 }

[
  {
    "x": "one",
    "y": [ -1, -2, -3 ],
    "title": null
  },
  {
    "x": "two",
    "y": [ 4, 5, 6 ],
    "title": null
  }
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions