Dynamic JSON
In areas where Retool expects an object
type input, you can use a superset of JSON to specify the object. Here are some examples of expressions that work (click on the JSON
tab to see the evaluation):
Normal ES5 JSON
Single quotes are supported.
"a string";
"another string";
"a string"
"another string"
Keys do not need to be in double quotes.
{
a: 1;
}
{ "a": 1 }
Numbers with decimals are supported.
1023.24;
1023.24
Trailing commas, single-line, and multi-line comments are allowed.
{
// name of user
name: 'Sarah',
age: 24,
/* list of roles user owns
note that user can have multiple roles */
roles: [
{ id: 1, name: 'engineer' },
{ id: 2, name: 'admin' },
],
}
{
"name": "Sarah",
"age": 24,
"roles": [
{
"id": 1,
"name": "engineer"
},
{
"id": 2,
"name": "admin"
}
]
}
Dynamic properties using {{ }}
{{ }}
You can use any valid expression inside {{ }} in your JSON.
{
name: {{ true ? 'Mary' : 'Chris' }},
description: "Owns {{ 2 }} {{ 'films' }}",
owned_films: {{ ['Jaws', 'Star Wars' ] }},
metadata: {{ { a: 1, b: 2, c: [] } }},
}
{
"name": "Mary",
"description": "Owns 2 films",
"owned_films": ["Jaws", "Star Wars"],
"metadata": {
"a": 1,
"b": 2,
"c": []
}
}
Dynamically adding properties to an object
Remove a key by setting the value to undefined
.
{
shouldShow: {{ true ? 'Hi 👋' : undefined }},
shouldHide: {{ false ? 'Bye 👻' : undefined }},
}
{
"shouldShow": "Hi 👋"
}
Updated 6 months ago