Selection

There are 7 types of selectoion:

Extraction

Used to extract data from the input.

  • Use . to get the input as is.
  • Use .<name> to access a key within an object. If the name has spaces, use the get function instead.
  • Use #<index> to access an element in an array.
  • Use ^ to access the "parent" input. That is, while in a functional function - like filter or map - use ^ to access the original input and ^^ to access the input of that input and so on.
  • One can use a combination of all of the aboove, i.e. ^.key-1.key-2#3.key-4.

Examples

  • For selection: . for input: {"key": 12} will produce: {"key": 12}.
  • For selection: .key-1.key-2 for input: {"key-1": {"key-2": 300}} will produce: 300.
  • For selection: .key-1.key-2 for input: {"key-3": {"key-2": 300}} will produce nothing.
  • For selection: .key-1#3 for input: {"key-1": ["a", "b", 3, "word", 6]} will produce: "word".
  • For selection: (.map (.map (.+ (size ^.) (size ^^.)))) for input: [[1, 2, 3], [4, 5], [6]] will produce: [[7, 8, 9], [9, 10], [10]].

Literal value

Used to select constant value. Use a simple JSON format. The input is ignored.

Examples

  • For selection: 4001.1 regardless of the input will produce: 4001.1.
  • For selection: null regardless of the input will produce: null.
  • For selection: "test" regardless of the input will produce: "test".
  • For selection: [1, 4, {}, 100] regardless of the input will produce: [1, 4, {}, 100].

Function

Invoke a function. Has a format of (<function-name> <arg0> <arg1> ..) where <argN> are other selection. Alternative format is (.<function-name> <arg1>...) - in that case, the first argument will be the input (i.e. .). The argument can be seperated by comma or whitespace. See list of available functions in functions additional help.

Examples

  • For selection: (len .) for input: [1, 4, {}, 100] will produce: 4.
  • For selection: (.len) for input: [1, 4, {}, 100] will produce: 4.
  • For selection: (len .list) for input: {"list": [1, 4, {}, 100]} will produce: 4.
  • For selection: (map (range 10) (+ . 5)) regardless of the input will produce: [5, 6, 7, 8, 9, 10, 11, 12, 13, 14].

Variables

Use a variable (either one the was predefined by the set command line argument or one that was defined by the set function). The format to use varaibles is :<variable-name>. Note that the variable is defiend once.

Examples

  • For selection: :nothing regardless of the input will produce nothing.
  • For selection: (set "length" (.len) (.map (.+ :length))) for input: [1, 2, 3] will produce: [4, 5, 6].

Macros

Use a macro (either one the was predefined by the set command line argument or one that was defined by the define function). The format to use a macro is @<variable-name>. Note that the macro is evelated on each call.

Examples

  • For selection: :nothing regardless of the input will produce nothing.
  • For selection: (define "even" (= 0 (.% 2)) (.filter @even)) for input: [1, 2, 3, 4, 5, 6, 7] will produce: [2, 4, 6].

Input context

Use input context to get the context of the input. The available input types are:

  • &index - To get the index of the current value within the current run.
  • &index-in-file - To get the index of the current value within the curent file.
  • &started-at-line-number - To get the line number within the input file in which the input started.
  • &started-at-char-number - To get the char number within the line within the input file in which the input started.
  • &ended-at-line-number - To get the line number within the input file in which the input ended.
  • &ended-at-char-number - To get the char number within the line within the input file in which the input ended.
  • &file-name - To get the name of the input file from which the input was parsed (will be empty for stdin input).

Examples

  • For selection: (- &ended-at-char-number &started-at-char-number) for input: "test" will produce: 6.

Previous selected values

Reuse previoulsy selected value. Use this to reuse a value that had been selected previously. This is not available during filtering, and one can only refere to values that had been selected before. The format is /<selection-name>/ where the selection-name is the name of the selection.

Examples

  • For selection: /name/ regardless of the input and previously selected name as "John" will produce: "John".
  • For selection: /name/ regardless of the input and previously selected name as nothing will produce nothing.
  • For selection: /name/ regardless of the input and previously selected Last Name as "Doe" will produce nothing.