Extract JSON
This page explains how the Extract JSON node can be used to pull arbitrary values out of a JSON object. It is most useful when coupled with the External API node or our API. A common use case of this node is to process a larger JSON response coming from the External API node. This is an advanced node.
Extract JSON node example
The left sidebar has three input fields to configure the node:
The first input defines a raw JSON string, or a field containing JSON to be processed.
The second input defines the JSON selector, which tells the chatbot where to find data in the JSON input. A selector may contain references to any user or bot fields by using curly braces like you would in a user message. the following are examples of valid selectors:
JSONSelector
Use the value stored in the
JSONSelector
field before reaching the node
/key1/user_field/0
Extract the value stored under
key1.user_field[0]
of the source JSONNote that user_field is used literally because it is not wrapped in curly braces.
/key1/{user_field}/{botField}
Extract the value stored under
key1.{user_field}.{botField}
{user_field}
and{botfield}
will be replaced based on the current user & bot session.
The third input defines where to store the resulting value if the value is found.
The Extract JSON box contains three outgoing paths: value found, not found, and unavailable.
value found : The selector found a value in the given JSON object.
not found: The selector does not match a value in the given JSON object.
invalid json: The given JSON object was not readable.
The chatbot will direct the flow according to the result value based on these paths. If the value is found, it will be stored as a variable under the name that is contained in the third input box on the left sidebar. If the value is not found or the source is invalid, the variable will be set to ‘not found’ or ‘invalid json‘ respectively.