JSON decode block
Purpose
Convert text into a JSON object or hold static data in a JSON format.
Most often used to hold static data.
Input
-
Execute
Executes when a truthy value is set. -
Value
Takes a text representation of a JSON object. If not connected, press the 'Edit default' button to create a default object with static data. The object can be as simple as just text, a number, a boolean or completely empty.
Output
- Object
Outputs an object.
Example
I have a single line text representation of my object. I cannot use the 'Get data' block on a single line of text. Therefore I need to convert it to an object first.
Text:
{ "node": { "id": "something unique", "type": "soda", "price": 3}}
The conversion:
graph LR A(Button) --Execute--> D(JSON decode) B([Text]) --Value--> D D --Value--> C([Object])
Caveats
If the object only has one value and not wrapped in {}
, it will output the value as it's data type and not an object. E.g. if the JSON decode block only contains this
"Here's a string of text"
The output type will be TEXT.