Skip to main content
Version: 3.3.0

convert

Converts data types of values

The types available

  • num
  • str
  • bool

Duration and memory units are available as well

  • kiB (also K) units of 1024
  • MiB (also M)
  • GiB (also G)
  • KB (units of 1000)
  • MB
  • GB
  • s seconds
  • ms (milliseconds)
  • us (microseconds)

Example

input:

{"value":"1GiB"}

action:

convert:
- value: KB

output:

{"value":1073741.824}

Example

input:

{"value":"1GiB"}

action:

convert:
- value: KiB

output:

{"value":1048576}

Example

input:

{"s":1,"number":"1"}

action:

convert:
- number: num

output:

{"s":1,"number":1}

Example: If incoming data has no unit, you can use special from/to conversion

input:

{"time": "500", "memory": 1}

action:

convert:
- time: ms/s # from millis to secs
- memory: G/M # from GiB to MiB

output:

{"time":0.5,"memory":1024}

Example: There is a special type called split

This takes values separated by either commas or spaces and make them into a JSON array.

input:

{"data":"1 two 3"}

action:

convert:
- data: split

output:

{"data":[1,"two",3]}
Field NameDescriptionTypeDefault
pairsConvert the following field: type pairsOrderedStringPairs-
fullAdditional conversion optionsConvertFull-

pairs

Convert the following field: type pairs

Type: OrderedStringPairs

full

Additional conversion options

Type: ConvertFull

Field NameDescriptionTypeDefault
conditionOnly run this action if the condition the specified condition is metexpression-
autoAllows auto-conversion, which helps when fields to be converted are numerousboolfalse
null-behaviourAllows auto-conversion, which helps when fields to be converted are numerousstring-
fieldsPairs of file names and types they should be converted toarray of (field,type) pairs-
no-warningBy default, convert complains if a field does not exist. Suppress with this fieldboolfalse

condition

Only run this action if the condition the specified condition is met

Type: expression

auto

Allows auto-conversion, which helps when fields to be converted are numerous

Type: bool

Example

input:

{"text":"one","number":"1"}

action:

convert:
auto: true

output:

{"text":"one","number":1}

null-behaviour

Allows auto-conversion, which helps when fields to be converted are numerous

Type: string

fields

Pairs of file names and types they should be converted to

Use this to exclude fields that would not convert correctly using auto

Type: array of (field,type) pairs

Example

input:

{"b":0,"number":"1"}

action:

convert:
auto: true
fields:
- b: bool

output:

{"b":false,"number":1}

no-warning

By default, convert complains if a field does not exist. Suppress with this field

Type: bool