The functions in this group help you parse the response of an external request: get the value you need from JSON or, the other way around, build JSON to send. You can pass a JSON string to these functions directly.
Where it helps:
- get a price, an order status or a link from an API response;
- get the list of keys to see what came in the response;
- prepare subscriber data to send to an external service.
Functions
| Function | Description | Example |
|---|---|---|
| json_parse(text) | Converts a JSON string into data you can work with using the functions in this section. | data = json_parse(client.api_response) |
| json_get(json, path, default) | Gets a value from JSON by a dot-separated path. List items are referenced by number, starting from 0. If there's no such value, returns default (empty by default). | json_get(client.api_response, 'items.0.price') → 1990 |
| get(collection, key, default) | Returns a list item by index (starting from 0) or a dictionary value by key. If there's no such item, returns default (empty by default). You can pass a JSON string directly. Unlike json_get, it reads only one level, without a dot-separated path. | get('["course", "book"]', 1) → "book" get('{"a": 1}', "b", 0) → 0 |
| to_json(value) | Converts a list or dictionary into a JSON string, for example to save it to a field or send it in an external request. | to_json(["course", "book"]) → '["course", "book"]' |
| dict_keys(dict) | Returns a list of the dictionary's keys. You can pass a JSON string directly. | dict_keys('{"a": 1, "b": 2}') → ["a", "b"] |
| dict_values(dict) | Returns a list of the dictionary's values. You can pass a JSON string directly. | dict_values('{"a": 1, "b": 2}') → [1, 2] |
Example: price and status from an API response
Suppose the external request response is saved to the api_response field:
{"items": [{"name": "Course", "price": 1990}], "status": "ok"}Get the data in the “Formula” step:
client.price = json_get(client.api_response, "items.0.price") client.status = get(client.api_response, "status") client.keys = join(dict_keys(client.api_response), ", ")
Result: price — 1990, status — ok, keys — items, status.
json_get follows a dot-separated path to any depth, while get reads only the first level. If there’s no such value, both functions return an empty value or whatever you pass as the third argument.
Example: build JSON to send
The subscriber listed their interests separated by commas. Turn them into a JSON list to pass to an external request.
client.interests_json = to_json(split_list(client.interests, ", "))
If the subscriber wrote yoga, running, interests_json gets ["yoga", "running"].
To add, remove or find an item in a list, see Formula: Lists.
If you did not find the answer to your question, feel free to contact us in the chat inside your dashboard, message us on Telegram at @BotHelpSupportBot, or email us at hello@bothelp.io.
Enjoy the full functionality of the BotHelp platform for creating broadcasts, automated funnels, and chatbots — free for 14 days.
Sign up for BotHelp
Get 14 days of full access for free — enough to build your first bot and test it on real subscribers.
Create account