Parse ndjson / Streaming API Data with make.com

Hi dear make.com Community,
i am requesting data from the SafetyCulture API https://developer.safetyculture.com/reference/answerservice_getanswersforinspection

The Streaming API type provides JSON data Sets which are only delimited by a new line for each data set.

How can i parse this data to my make.com workflow to be able to address the single objects within it?

Just use a parse JSON module:

Yeah sure… but how to use the newline as delimiter within that module? The JSON Parser thinks it is not valid json since it is multiple json objects seperated by a new line.

For further assistance, please provide the following:

Please provide screenshots and a sample output bundle from this module demonstrating the issue.

1 Like

Do you have the parse response on in your http call?

I think what they meant is NDJSON format is not JSON, so the HTTP module and even Parse JSON module can not parse it…

I swear I’ve seen something like this before on the forum but I can’t seem to find it using search.

Anyway, a feature request should be created for NDJSON parsing.

1 Like

Sorry, i thought this is potentially not needed based on the example in the api spec above. Here is a data sample:

{"result":{"question_id":"9192e9f4-69c8-445c-b3b9-337a1d560916","modified_at":null,"question_answer":{"responses":[],"note":"","media":[],"attachments":null},"location":null}}
{"result":{"question_id":"f3245d42-ea77-11e1-aff1-0800200c9a66","modified_at":"2022-07-06T19:35:59Z","datetime_answer":{"answer":"2022-07-05T22:00:00Z","attachments":null},"location":null}}
{"result":{"question_id":"f3245d43-ea77-11e1-aff1-0800200c9a66","modified_at":"2022-07-06T19:32:36Z","text_answer":{"answer":"Manfred Mustermann","attachments":null},"location":null}}

These are three sets of results.

In addition two screenshots of the modules.


I have an idea but I’m already in bed. Will get to it in the morning after some testing, if nobody else has a solution by then.

I figured it out like this it is a little hacky maybe sam can help tomorrow with a better solution.

Split the http call at the closing brackets:

Iterate over the split

Parse the value and add the closing bracket back in:

Aggerate back together if you’d like

the issue with your JSON is:
It contains multiple JSON objects, but they are not structured within a single valid JSON format. JSON must have a single root element, either an object {} or an array [].

I think you built a really nice solution here, if someone stumbles accross this i would recommend @Mr.Make 's approach. However i solved it by using str_replace to add up the commas:

{{replace(“[” + replace(3.data; “”“location”“:null}}”; “”“location”“:null}},”) + “]”; “,]”; “]”)}}

The inner replace checks for every “location”:null}} - which i can be certain the data ends with. The outer one removes the last comma of the array.

Thank you all a lot.

1 Like

Glad its solved nice work!

A. Parse JSON with functions + (optional) map Method

Yes, that is possible. You’ll need just one module (one operation):

Screenshot_2024-08-30_090831

A second optional module can be used to map out the inner collection.

Screenshot_2024-08-30_090842

Example Output

Screenshot_2024-08-30_090851

Module Export - quick import into your scenario

You can copy and paste this module export into your scenario. This will import the modules (with fields/settings/filters) shown in my screenshots above.

  1. Move your mouse over the line of code below. Copy the JSON by clicking the copy button on the right of the code, which looks like this:

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the editor.

  3. Click on each imported module and re-save it for validation. There may be some errors prompting you to remap some variables and connections.

JSON module export — paste this directly in your scenario

{"subflows":[{"flow":[{"id":14,"module":"util:ComposeTransformer","version":1,"parameters":{},"mapper":{"value":"{\"result\":{\"question_id\":\"9192e9f4-69c8-445c-b3b9-337a1d560916\",\"modified_at\":null,\"question_answer\":{\"responses\":[],\"note\":\"\",\"media\":[],\"attachments\":null},\"location\":null}}\n{\"result\":{\"question_id\":\"f3245d42-ea77-11e1-aff1-0800200c9a66\",\"modified_at\":\"2022-07-06T19:35:59Z\",\"datetime_answer\":{\"answer\":\"2022-07-05T22:00:00Z\",\"attachments\":null},\"location\":null}}\n{\"result\":{\"question_id\":\"f3245d43-ea77-11e1-aff1-0800200c9a66\",\"modified_at\":\"2022-07-06T19:32:36Z\",\"text_answer\":{\"answer\":\"Manfred Mustermann\",\"attachments\":null},\"location\":null}}"},"metadata":{"designer":{"x":-48,"y":-342,"name":"Sample NDJSON"}}},{"id":15,"module":"json:ParseJSON","version":1,"parameters":{"type":""},"mapper":{"json":"{\"items\":[\n{{join(split(14.value; newline); \",\")}}\n]}"},"metadata":{"designer":{"x":197,"y":-342},"parameters":[{"name":"type","type":"udt","label":"Data structure"}]}},{"id":16,"module":"util:SetVariable2","version":1,"parameters":{},"mapper":{"name":"items","scope":"roundtrip","value":"{{map(15.items; \"result\")}}"},"metadata":{"designer":{"x":440,"y":-343,"name":"Map inner collection"}}}]}],"metadata":{"version":1}}

Note: Did you know you can reduce the size of blueprints and module export code like the above, using the Make Blueprint Scrubber?

Hope this helps! Let me know if there are any further questions or issues.

— @samliew


P.S.: Did you know, the concepts of about 70% of questions asked on this forum are already covered in the Make Academy. Investing some effort into it will save you lots of time and frustration using Make later!

B. JavaScript Method

This combines both modules above (including the optional module), into just one operation.

Sample Output

Module Export - quick import into your scenario

You can copy and paste this module export into your scenario. This will import the modules (with fields/settings/filters) shown in my screenshots above.

  1. Move your mouse over the line of code below. Copy the JSON by clicking the copy button on the right of the code, which looks like this:

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the editor.

  3. Click on each imported module and re-save it for validation. There may be some errors prompting you to remap some variables and connections.

JSON module export — paste this directly in your scenario

{"subflows":[{"flow":[{"id":21,"module":"custom-js:inlineexecutev2","version":1,"parameters":{"__IMTCONN__":2457341,"jscode":"return JSON.parse(`{\"items\":[${input.replace(/\\n+/g, \",\")}]}`)\n  .items?.map(v => Object.values(v).shift() ?? v);","returnValueType":"collection"},"mapper":{"input":"{{20.value}}"},"metadata":{"designer":{"x":205,"y":-747,"name":"Parse NDJSON"},"parameters":[{"name":"__IMTCONN__","type":"account:custom-js2","label":"Connection","required":true},{"name":"jscode","type":"text","label":"JavaScript Code","required":true},{"name":"returnValueType","type":"select","label":"Return Type","required":true,"validate":{"enum":["text","collection","array","binary"]}}]}}]}],"metadata":{"version":1}}

Note: Did you know you can reduce the size of blueprints and module export code like the above, using the Make Blueprint Scrubber?

Store the function in CustomJS itself

If you use the function frequently, you can save the code in CJS and then select the function using the “Execute Stored Function” module.

Screenshot_2024-08-30_100806

How to set-up a FREE Custom JS connection?

  1. Go to the app’s website and click “Create Account”.

  2. Once logged in, on the right-hand side, click on the “Show” link. Copy the API key.

  3. Click “Create a connection” in the Custom JS module:

  4. Paste API key and click Save:

How to use the Custom JS module?

  1. Map a variable (or a JSON object) into the “Input” field.

  2. Write a function to do something with the input variable. If the input is a JSON, you can reference object properties using dot notation.

  3. Write a final statement to return the call of the function you wrote.

Further Information

If you need help with using Custom JS modules, please create a new thread. This helps keep the forum organized and helps me get to your question faster.

You can also take a look at the official documentation here for more advanced usage: