Skill level: Intermediate
Time required: 5 minutes
This article demonstrates how to handle uncluttered JSON strings and convert them to a structured JSON object format using JSON Parser by Quickwork.
Prerequisites
- A Quickwork account and and familiarity with the platform's GUI.
What is JSON
JSON (JavaScript Object Notation) is a popular data format that uses name-value pairs and arrays for its structure, known for its simplicity and ease of readability. Although JSON data is typically displayed in a user-friendly format, there are instances where you may need to process raw, unformatted JSON data. In such situations, the JSON Parser can be utilized to convert raw data into a well-structured JSON format for streamlined handling.
The JSON Parser can handle:
- An object of raw JSON data
- An array of objects containing raw JSON data
Rules for specifying the raw JSON data:
- Enclose data in curly braces {} for objects or square brackets [] for arrays.
- Do not include a trailing comma , after the last JSON object in an array.
- Enclose string key-value pairs in double quotes "".
Violation of any of the above rules may throw an error as Bad request.
Passing a string containing JSON object(s)
- Under the Event section, choose the Scheduler by Quickwork app from the drop-down menu in the Apps field present right below the New Trigger button.
- Select the trigger event, New scheduled event, from the drop-down menu in the Triggers field.
- Set the Interval based on your requirement depending on how frequently you want the journey to be executed.
- Set the date and time of your choice in the Start At field and keep the Custom Payload field empty.
- Under the Steps section, click on the Simple Action button and choose the JSON Parser by Quickwork app from the drop-down menu in the Apps field.
- Select Parse string to JSON from the drop-down menu in the Actions field.
- In the String field, input raw JSON data or a data pill containing JSON objects. For example, { "userId": 123, "id": 40, "Name": "Mr. John Snow", "Designation": "Sr. Software Engineer"}
- In the Sample JSON field, define the desired JSON structure. For example:
{
"user_id": 1,
"personal_id": 4,
"full_name": "",
"job_profile": ""
}
Note:
Keys with integer values require a dummy integer in the syntax, for example, "key": 1
Keys with string values require a null string in the syntax, for example, "key": ""
Failing to define the syntax properly may lead to errors in subsequent actions - Save the changes and start the journey. Go to the History section and check the execution details.
- The Input block of JSON Parser contains:
- document: The raw JSON data that needs to be parsed.
- sampleDocument: The syntax for the JSON response.
- The Output block contains the structured JSON data.
Passing an array of objects containing raw JSON data
- In the String field, input an array of JSON objects. For example:
[
{"userId": 10, "id": 12343, "name": "Mr. Andrew Flintoff", "designation": "Technical writer"},
{"userId": 10, "id": 62743, "name": "Mrs. Stefie Hall", "designation": "Production designer"},
{"userId": 10, "id": 76348, "name": "Mr. Roman Hall", "designation": "Developer"}
] - In the Sample JSON field, define a syntax for JSON response. Similar to parsing a single JSON object, define the syntax for one JSON object in the array.
- Upon successful execution, the array is converted into structured JSON.
4. The respective keys become data pills in the Data Tree Output, ready for use in subsequent actions.
By following these steps, you can seamlessly parse and structure raw JSON data, enabling efficient processing and integration in Quickwork.
Comments
0 comments
Please sign in to leave a comment.