Skip to main content
All CollectionsWrk Action LibraryText
Retrieve values from JSON
Retrieve values from JSON
Wrk Product avatar
Written by Wrk Product
Updated this week

Retrieve values from a provided JSON. Use JSON path to indicate the text to be retrieved from the JSON.

You can find more information on how to use JSON path at this link: https://pypi.org/project/jsonpath-ng/

Application

  • Text

Inputs (what you have)

Name

Description

Data Type

Required?

Example

JSON Text

Text in JSON format that you are looking to retrieve values from

Text (Long)

Yes

{“key”:”value”}

JSON path

The JSON path to the object or value in the text you would like to retrieve.

Text (Long)

Yes

$.key

Fields to capture name

The name of the field to capture in which to add the JSON value

Text (Short)

Yes

Field1

Format outputs as an array?

Format outputs as an array

True/False

No

True

Note: the value of inputs can either be a set value in the configuration of the Wrk Action within the Wrkflow, or a variable from the Data library section. These variables in the Data library section are the outputs of previous Wrk Actions in the Wrkflow.

Outputs (what you get)

Name

Description

Data Type

Required?

Example

Fields to capture

A new field to add the value from the input JSON. This field name must match the value in New field name

Text (Long)

Yes

Field1

Outcomes

Name

Description

Success

This status is selected if details are extracted from the JSON.

No result

This status is selected in the event of the following scenarios:

  • None of the provided fields to capture found keys in the provided JSON

Unsuccessful

This status is selected in the event of the following scenarios:

  • The input text is not in JSON formatting and could not be converted.

JSON Path Configuration Instructions

Atomic expressions:

Syntax

Meaning

$

The root object

`this`

The “current” object.

`foo`

More generally, this syntax allows “named operators” to extend JSON path in arbitrary ways

field

Specified field(s), described below

[ field ]

Same as field

[ idx ]

Array access, is described below (this is always unambiguous with field access)

Jsonpath operators:

Syntax

Meaning

jsonpath1 . jsonpath2

All nodes matched by jsonpath2 starting at any node matching jsonpath1

jsonpath [ fieldname ]

Same as jsonpath.fieldname

jsonpath1 .. jsonpath2

All nodes matched by jsonpath2 that descend from any node matching jsonpath1

jsonpath1 where jsonpath2

Any nodes matching jsonpath1 with a child matching jsonpath2

jsonpath1 | jsonpath2

Any nodes matching the union of jsonpath1 and jsonpath2

Field specifiers ( field ):

Syntax

Meaning

fieldname

the field fieldname (from the “current” object)

"fieldname"

same as above, for allowing special characters in the fieldname

'fieldname'

ditto

*

any field

field , field

either of the named fields (you can always build an equivalent JSON path using |)

Array specifiers ( idx ):

Syntax

Meaning

[n]

array index (may be comma-separated list)

[start?:end?]

array slicing

[*]

any array index

Functions

name

Example

len

  • $.objects.`len`

keys

  • $.objects.`keys` (will return all keys in the object)

str()

  • $.objects.`str()` (converts response to string)

sub

Surround your regex with /regex/

  • $.field.`sub(/foo\\+(.*)/, \\1)`

  • $.field.`sub(/regex/, replacement)`

split

  • $.field.`split(+, 2, -1)`

  • $.field.`split(sep, segement, maxsplit)`

*the spaces after the separating commas are required

sorted

  • $.objects.`sorted`

  • $.objects[/some_field]

  • $.objects[/some_field,/other_field]

*Use / to sort ascending and \ to sort descending

filter

  • $.objects[?(@some_field > 5)]

  • $.objects[?some_field = 'foobar']

  • $.objects[?some_field =~ 'foobar']

  • $.objects[?some_field > 5 & other < 2]

Supported operators:

  • Equality: ==, =, !=

  • Comparison: >, >=, <, <=

  • Regex match: =~

  • Combine multiple criteria with: &

Properties can only be compared to static values.

Note: If filtering using =~ then the entire array being filtered must be objects or strings. You cannot use this feature for integers, boolean, or nulls.

arithmetic (-+*/)

  • $.foo * 12

  • $.objects[*].cow + $.objects[*].cat

String joins / concatenation

  • $.objects[*].first_name + ' ' + $.objects[*].last_name


Version# 1.0

Did this answer your question?