collapse

Converts JSON records to another format, like CSV or key-value pairs

This is the opposite action to expand. You must specify output-field to receive the result.

Field NameDescriptionTypeDefault
delimA separator of output valuesstring,
input-fieldField containing datafield-
output-fieldA field where data is to be writtenfield-

collapse csv

JSON to CSV

Type: enum

Field NameDescriptionTypeDefault
header-fieldWrite the column names to this fieldstring-
header-field-typesWith header-field, write out column names and typesboolfalse
header-field-on-changeWith 'header-field`, only write out headers if columns changeboolfalse
null-valuehow to represent fields with null valuesstring

header-field

Write the column names to this field

Type: string

Example

input:

{"one":1,"two":2}

action:

collapse:
  csv:
    header-field: header
  output-field: row

output:

{"row":"1,2","header":"one,two"}

header-field-types

With header-field, write out column names and types

Type: bool

Example

input:

{"one":1,"two":2}

action:

collapse:
  csv:
    header-field: header
    header-field-types: true
  output-field: row

output:

{"row":"1,2","header":"one:num,two:num"}

header-field-on-change

With 'header-field`, only write out headers if columns change

Type: bool

Example

input:

{"a":1,"b":"one"}
{"a":2,"b":"two"}

action:

collapse:
  csv:
    header-field: header
    header-field-on-change: true
  output-field: row

output:

{"row":"1,one","header":"a,b"}
{"row":"2,two"}

null-value

how to represent fields with null values

Type: string

Example

input:

{"num":1,"str":"one"}
{"num":2,"str":"two"}
{"num":null,"str":"NaN"}

action:

collapse:
  csv:
    null-value: '-'
  output-field: row

output:

{"row":"1,one"}
{"row":"2,two"}
{"row":"-,NaN"}

collapse key-value

???

Type: enum

Field NameDescriptionTypeDefault
key-value-delimseparator between the key and the valuestring=

key-value-delim

separator between the key and the value

Type: string

Example: override usual '='

input:

{"one":1,"two":2}

action:

collapse:
  key-value:
    key-value-delim: ':'
  output-field: row

output:

{"row":"one:1,two:2"}

Example: delimiters and separators can be special or multiple

this converts JSON to Prometheus text format

input:

{"one":1,"two":2}

action:

collapse:
  delim: '\n'
  key-value:
    key-value-delim: '{pipe="metrics"} '
  output-field: row

output:

{"row":"one{pipe=\"metrics\"} 1\ntwo{pipe=\"metrics\"} 2"}

collapse array

???

Type: enum

Field NameDescriptionTypeDefault
collect-over-fieldThis is useful when processing the output of transitionstring-

collect-over-field

This is useful when processing the output of transition

Type: string

Example

input:

{"one-two":[{"num":1,"str":"one"},{"num":2,"str":"two"}]}

action:

collapse:
  input-field: one-two
  array:
    collect-over-field: num
  output-field: row

output:

{"row":"1,2"}

delim

A separator of output values

Type: string

Example

input:

{"one":1,"two":2}

action:

collapse:
  csv: true
  output-field: row
  delim: ' | '

output:

{"row":"1 | 2"}

input-field

Field containing data

Type: field

output-field

A field where data is to be written

Type: field

Example

input:

{"one":1,"two":2}

action:

collapse:
  csv: true
  output-field: row

output:

{"row":"1,2"}