Skill level: Intermediate
Time required: 5 minutes
This article explains how to troubleshoot and resolve issues related to stringified JSON data obtained via HTTP, ensuring you receive proper JSON responses in your output.
Prerequisites
- HTTP trigger
- Logger app
- An API testing tool, such as Postman
Consider an example to demonstrate the correct execution of an HTTP trigger with a suitable payload.
Step-by-step guide
1. Configuring the HTTP trigger
- Navigate to the Event section and select the HTTP app from the drop-down menu in the Apps list.
- Select the New request on HTTP link trigger.
- Enter a name for the webhook in the Webhook name field. For example, Demo Event. This will generate a webhook URL.
- Select HTTP method as POST:
- Specify the following JSON body in the Request payload (Body) field.
2. Configuring the Logger action
- In the Steps section, click Simple Action and select the Logger app from the drop-down menu.
- Choose the Log a Message action.
- Drag and drop the Field1 data pill from the HTTP | New Request on HTTP link Trigger in the Data Tree Output to the Message input field.
- Click Save & Start.
3. Executing the journey
- Copy the webhook URL from the triggers section.
- Open an API testing tool, f Postman and paste the URL into the request field.
- Set the request method to POST.
- In the Body section, set the content type to JSON and paste the same JSON body as defined in the journey.
- Click Send. You should receive an OK response.
- Go to the History tab in your journey.
- The payload is parsed into JSON format under the HTTP trigger Output.
- The Logger app logs the appropriate values.
Troubleshooting stringified JSON data
If JSON data appears as a string, it may be due to one of the following issues:
1. Mismatch in request method
- Ensure the request method in your API testing tool matches the one configured in the journey For example, both should be POST.
- Using different methods, such as POST in the journey and GET in the testing tool, will
- Result in an empty payload.
- Produce no logged message in the Logger app.
2. Inappropriate request header
- The content type for the JSON body must be application/json.
- Ensure the body parameter type is set to raw - JSON. Other types, such as urlencoded, GraphQL, or form-data, will not work and will return an empty payload.
3. Invalid JSON data
As illustrated in the example below, invalid JSON data specified in the JSON body, whether in a journey or an API testing tool, results in a stringified output.
In this case, the HTTP trigger's output contains string values despite the body being defined in JSON format. Additionally, no response is logged.
Follow these rules for valid JSON syntax:
- JSON data must be enclosed within curly braces {}.
- Keys and string values must be wrapped in double quotes. For example, "name":"john".
- End each key-value pair with a comma, except for the last one.
- Do not include a trailing comma after the final key-value pair or closing curly brace.
Examples of valid JSON data
Single key-value pair |
Multiple key-value pairs |
{ "name": "john" } |
{ "name": "john", "age":25, "city":"mumbai" } |
Examples of invalid JSON data
JSON Data |
Reason for invalidity |
{ "name": john } |
Missing double quotes around the string value. |
{ "name": "john", "age":25 "city":"mumbai" } |
Missing comma after second single key-value pair. |
{ "name": "john", "age":25, "city":"mumbai" }, |
A comma after the closing curly bracket is invalid. |
{ "name": "john", } |
A comma is unnecessary when there is only a single key-value pair in the JSON object. |
{ "name": "john", "age":"25", "city":"mumbai", }, |
Trailing comma after the last key-value pair. |
age:23 |
JSON data defined with invalid syntax. |
Comments
0 comments
Please sign in to leave a comment.