Source Is Not Valid JSON Error (Source Is Valid JSON)

I’m sending a webhook response from one scenario, containing stringified JSON to a HTTP module in other scenario.

The stringified JSON is:

"{\n    \"Unavailable\": [],\n    \"Away\": [\"77e8aebf-28fd-4906-b602-353fbd40b298\", \"77e8aebf-28fd-4906-b602-353fbd40b298\"],\n    \"Preference\": [\"77e8aebf-28fd-4906-b602-353fbd40b298\"],\n    \"Available\": []\n}"

which produces this JSON when it’s parsed:

{
    "Unavailable": [],
    "Away": [
        "77e8aebf-28fd-4906-b602-353fbd40b298",
        "77e8aebf-28fd-4906-b602-353fbd40b298"
    ],
    "Preference": [
        "77e8aebf-28fd-4906-b602-353fbd40b298"
    ],
    "Available": []
}

I’ve set my HTTP module to parse the response but its output is shown as the parsed JSON in the UI -

or the stringified JSON when I use view the output bundles -

But when I try to parse that JSON in another step, I get an error “Source Is Not Valid JSON”. When I run the Parse JSON module on its own and copy and paste the output from the HTTP module as the content, it’s parsed successfully. Whyyyyyyyyyyyy?

In case it’s relevant, the content encoding of the JSON is shown as br in the Integromat developer tools.

I recreated your flow—you are probably missing the content type in the webhook response.

Try adding custom headers:

  • Key: Content-type
  • Value: application/json

Zrzut ekranu 2024-07-11 o 17.14.42

Results:

2 Likes

You don’t need to pre-stringify/clean/escape the JSON before you insert it into the HTTP Content field.

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

3 Likes

Thanks for the reply but if I don’t stringify the JSON - so the body of the webhook response is:

{
    "Unavailable": [],
    "Away": ["77e8aebf-28fd-4906-b602-353fbd40b298", "77e8aebf-28fd-4906-b602-353fbd40b298"],
    "Preference": ["77e8aebf-28fd-4906-b602-353fbd40b298"],
    "Available": []
}

Then I get an error in the HTTP module:

Response body is not a valid JSON. Unexpected token ’ ', …“bd40b298”, “77e8aebf”… is not valid JSON

To avoid any confusion the process is:

  1. HTTP module sends request to another scenario’s webhook
  2. Other scenario’s webhook fetches the content which I am trying to send back to the HTTP module in the webhook response
  3. HTTP module receives that content and throws that error

The response content is:

I was able to reproduce the error, with a non-standard whitespace character.

Example:

Green - Normal space
Red - Em space

Screenshot_2024-07-12_090718

Make sure you are not using any invalid spaces like these.

The reason why nobody found an answer earlier, is because this forum software normalizes (converts) all the different types of spaces to the standard space, so it becomes valid JSON when you pasted the output bundles in this forum.

You can try manually deleting and retyping all spaces again, even in the aggregator modules separator field.

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

3 Likes

Apologies, I missed this reply. I had set the content type for my webhook response -

Nice idea but I’ve just tried removing all spaces from my response and unfortunately that doesn’t fix the issue. This is the only module where I’m adding spaces and I’ve double checked that I’ve not added trailing whitespace, for example, elsewhere in the scenario.

I’ll need the full scenario blueprint and output bundle of module 39.

2. Scenario blueprint

Please export the scenario blueprint file to allow others to view the mappings and settings. At the bottom of the scenario editor, you can click on the three dots to find the Export Blueprint menu item.

Screenshot_2023-08-24_230826
(Note: Exporting your scenario will not include private information or keys to your connections)

Uploading it here will look like this:

blueprint.json (12.3 KB)

3. And most importantly, Output bundles

Please provide the output bundles of the modules by running the scenario, then click the white speech bubble on the top-right of each module and select “Download output bundles”.
Screenshot_2023-10-06_141025

A.

Save the bundle contents in your text editor as a bundle.txt file, and upload it here into this discussion thread.

Uploading it here will look like this:

bundle.txt (12.3 KB)

B.

If you are unable to upload files on this forum, alternatively you can paste the formatted output bundle in this manner:

  • Either add three backticks ``` before and after the code, like this:

    ```
    input/output bundle content goes here
    ```

  • Or use the format code button in the editor:
    Screenshot_2023-10-02_191027

Providing the output bundles will allow others to replicate what is going on in the scenario even if they do not use the external service.

Following these steps will allow others to assist you here. Thanks!

samliewrequest private consultation

Join the unofficial Make Discord server to chat with us!

Alright so I’ve done some more testing and it looks like you were right about a space causing the issue, when I set the content of my webhook response to:

{
    "Unavailable": [{{39.Unavailable}}],
    "Away": [{{39.Away}}],
    "Preference": [{{39.Preference}}],
    "Available": [{{20.text}}]
}

Make inserts a space between the two items in the Away array. When I copy and paste the raw content into the webhook response:

	{
    "Unavailable": [],
    "Away": ["77e8aebf-28fd-4906-b602-353fbd40b298", "77e8aebf-28fd-4906-b602-353fbd40b298"],
    "Preference": ["77e8aebf-28fd-4906-b602-353fbd40b298"],
    "Available": []
}

I get an the ‘invalid JSON’ error. When I remove the space after the first item in the Away array:

	{
    "Unavailable": [],
    "Away": ["77e8aebf-28fd-4906-b602-353fbd40b298","77e8aebf-28fd-4906-b602-353fbd40b298"],
    "Preference": ["77e8aebf-28fd-4906-b602-353fbd40b298"],
    "Available": []
}

I don’t get an error. Fun times.

So that leaves my trying to figure out how to remove that space. Using remove and replace doesn’t work. Do you know how I can stop Make from adding it / remove it from the response content?

The Away array content that I’m inserting into the response is just an array like this -

CleanShot 2024-07-12 at 14.47.22@2x

You should probably be using the join function to join the array items by a comma instead of leaving it to chance (auto joining with comma AND a non-standard space).

{{ join(39.away; ",") }}

By directly mapping an array into a field, you are telling make to do whatever they want to convert the array into a string, and that happens to use something that breaks JSON.

samliewrequest private consultation

Join the unofficial Make Discord server to chat with us!

4 Likes

Thanks! For the benefit of anyone else who runs into this, this is the formatted webhook response -

4 Likes