Search HoldMyTwist

Browse all posts

Make Parse JSON: turn text into usable fields

Compare two bundles from a top level array with one bundle from an object with the same array in it.

A JSON response could appear like one big text. Make's Parse JSON module (opens in a new tab) will parse it to have fields you can use in subsequent steps.

Before you start

First, you will need an account on Make. You can create a Make Free account (opens in a new tab) or login. For this exercise you can do it without integrating another app.

This is an example using the imaginary data and the built-in modules in Make Free. You need to set your scenario to Inactive. You should set to Run once.

1. Add the JSON input

  1. On the Scenarios page, click Create scenario. Change the name in the top left (scenario name) to JSON fields practice.
  2. Click on the big plus. Select JSON. Select Parse JSON.
  3. Don't fill the Data structure for now. For the practice, you're going to paste the example to the JSON string area.
  4. Save the module by clicking Save on the module. Save the canvas by clicking Save on the canvas. If you get a warning message saying output not used, click on Save anyway.
Text to copy

{"item":"Notebook","quantity":2}

2. Run the source before mapping it

  1. click run once if you get the same warning about unused output again click run anyway
  2. click on the result bubble at the top of JSON module
  3. check the output there should be 1 record (in Make called bundle) - item: Notebook quantity: 2

Quick takeaway

Make sure to run the source for JSON before adding the next step. Make might not show you the fields in the mapping panel if you don't have a saved structure or a seen result. Make sure to verify what the actual result is, and then pick that field from the module.

3. Use one field in the next module

  1. Hide results panel
  2. Click on plus next to JSON module on the right
  3. Select Tools -> Set variable
  4. Enter item_label for Variable name
  5. Click Variable value. In map panel click on JSON 1 - Parse JSON on expand tree and select item - it should be coloured token now
  6. Save module and scenario. Click again on Run once

Open Tools result bubble. Output should have item_label: Notebook You are using a parsed field without sending it to another service.

If a field is missing

Run Parse JSON with sample "typical" data again. Then go back to the next module. Make sure you picked the token from the JSON module and the source has this field.

Before you invoke Make, have the fake sample checked in JSONLint. Don't paste real secrets or data. E008 is indicating closing brace. Remove trailing comma after quantity in the line above. Then validate again. And even with the syntax correct you need to look at field presence and value types.

Text to copy

{
"item": "Notebook",
"quantity": 2,
}

One JSON object equals one bundle. One top level array equals one bundle per item. See Make's JSON docs (opens in a new tab).

Keep track of the number of output bundles before adding any modules that emit messages/create records.

When do you need an Iterator? Compare these two shapes (with scenario in Inactive). You leave blank in Data structure for this extra check.

A top-level array

Text to copy

[
{"item":"Notebook","quantity":2},
{"item":"Pencil","quantity":1}
]

  1. Copy-paste JSON string above to replace JSON string. Save module and scenario, and click Run once.
  2. After you've run through the top level array example, look at the result bubble (above Parse JSON) and see how many output bundles there are. It should have 2 - one for Notebook and one for Pencil. Before plugging in a module that sends messages or creates records, please verify how many bundles there are. Parse JSON breaks top-level array into individual items, each with its own bundle. They are already separated. No need for Iterator in this case.

An array inside an object

Text to copy

{"items":[
{"item":"Notebook","quantity":2},
{"item":"Pencil","quantity":1}
]}

  1. Then you take your 2nd input (which is JSON string) and swap that in. Save the module. Then right click Parse JSON and select "run this module only" so that the Tools mapping won't get run against something different.
  2. Expand that output and you'll have a single bundle with an items[] array with both records. Use the Iterator practice when you want to split up an array field into separate bundles.

To test it, you want to put in [] and just run Parse JSON. Do you see any bundles coming back from the module? Then just make sure to put in the original JSON object again in the JSON string field and save the module.

Don't have an account yet? Get started with Make Free (opens in a new tab). Check out the guide on the Free plan before you add your routine to a scheduled workflow.

Share this post