Skip to main content
Version: 3.5.3

Action: 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"}

Pipe Language Snippet:

convert:
- value: KB

Output:

{"value":1073741.824}

Example

Input:

{"value":"1GiB"}

Pipe Language Snippet:

convert:
- value: KiB

Output:

{"value":1048576}

Example

Input:

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

Pipe Language Snippet:

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}

Pipe Language Snippet:

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

Input:

{"data":"1 two 3"}

Pipe Language Snippet:

convert:
- data: split

Output:

{"data":[1,"two",3]}

Field Summary

Field NameTypeDescriptionDefault
pairsOrderedStringPairsConvert the following field: type pairs-
fullConvertFullAdditional conversion options-

Fields

pairs

Type: OrderedStringPairs

Convert the following field: type pairs

full

Type: ConvertFull

Additional conversion options

Field NameTypeDescriptionDefault
conditionexpressionOnly run this action if the condition the specified condition is met-
autoboolAllows auto-conversion, which helps when fields to be converted are numerousfalse
null-behaviourstringAllows auto-conversion, which helps when fields to be converted are numerous-
fieldsarray of (field,type) pairsPairs of file names and types they should be converted to-
no-warningboolBy default, convert complains if a field does not exist. Suppress with this fieldfalse

  condition

Type: expression

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

  auto

Type: bool

Default: false

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

Example

Input:

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

Pipe Language Snippet:

convert:
auto: true

Output:

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

  null-behaviour

Type: string

Possible Values: keep, default

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

  fields

Type: array of (field,type) pairs

Pairs of file names and types they should be converted to

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

Example

Input:

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

Pipe Language Snippet:

convert:
auto: true
fields:
- b: bool

Output:

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

  no-warning

Type: bool

Default: false

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