JSON formatting break line

Hi,

I have this JSON:

[
    {
        "method": "offer.update",
        "params": [
           4645 ,
            {
              "tags": [
                657, 660
                ]
            }
        ],
        "id": 4645
    }
]

The problem is that the tag ID’s are on one line.

What I try is this:

[
    {
        "method": "offer.update",
        "params": [
            ,
            {
              "tags": [
                {{replace(join(4.tags; ","); ","; ",\\n")}}
                ]
            }
        ],
        "id": 
    }
]

But then I get this: 657,\n777,\n660

Is there somebody willing to help me?

Greetings,
Robin

Hi @uitholland,

What you have is an array of integers. Is this an input or output of a module? And what is the result you are expecting, do you want a string with comma separated values?

Cheers,
Henk

HI @Henk-Operative,

Yes, it is an array which I convert to string with join().

For parsing this output it is wrong, it has to be (with break line)

657,
660

So what I try is to replace the comma with ,\n.

But the is no break line just the characters.

Can you show us the blueprint or screenshots of your scenario? In JSON, it shouldn’t matter whether the items in the tags array (or any array) are placed on new lines or not. What matters is that the items are separated by commas. The formatting (whether each item is on its own line or all on one line) is for human readability and does not affect the validity of the JSON.

See:

So there is no issue with this format, but maybe I don’t have a good understanding of what you are trying to accomplish. Please correct me if I don’t.

Now, it is possible to turn an array into a comma separated list with your syntax. Try to use {{newline}} instead of \n.

Cheers,
Henk

When I use this:


I get this:

When I validate the JSON online with https://jsonlint.com it changes:
657,777,660

657,
777,
660

When I executer it that will it will perform good.

The output in the last screenshot is not the output of the module in the first screenshot. Also notice that the JSON object is wrapped in an array.

What module/service/endpoint are you using that returns the syntax error, and can you share the input and output bundles of it?

Cheers,
Henk

Input:

[
    {
        "ca": null,
        "qs": [],
        "url": "https://api.gripp.com/public/api3.php",
        "data": "[\n    {\n        \"method\": \"offer.update\",\n        \"params\": [\n           4639 ,\n            {\n              \"tags\": [\n                657, 660\n                ]\n            }\n        ],\n        \"id\": 4639\n    }\n]",
        "gzip": true,
        "method": "post",
        "headers": [
            {
                "name": "Authorization",
                "value": ""
            }
        ],
        "timeout": null,
        "useMtls": false,
        "authPass": null,
        "authUser": null,
        "bodyType": "raw",
        "contentType": "application/json",
        "serializeUrl": false,
        "shareCookies": false,
        "parseResponse": true,
        "followRedirect": true,
        "useQuerystring": false,
        "followAllRedirects": false,
        "rejectUnauthorized": true
    }
]

Output:

[
    {
        "statusCode": 200,
        "headers": [
            {
                "name": "server",
                "value": "nginx"
            },
            {
                "name": "date",
                "value": "Wed, 16 Oct 2024 06:15:03 GMT"
            },
            {
                "name": "content-type",
                "value": "text/html; charset=utf-8"
            },
            {
                "name": "transfer-encoding",
                "value": "chunked"
            },
            {
                "name": "connection",
                "value": "keep-alive"
            },
            {
                "name": "x-robots-tag",
                "value": "noindex"
            },
            {
                "name": "x-ratelimit-limit",
                "value": "1000"
            },
            {
                "name": "x-ratelimit-remaining",
                "value": "993"
            },
            {
                "name": "access-control-allow-origin",
                "value": "*"
            },
            {
                "name": "access-control-allow-credentials",
                "value": "false"
            },
            {
                "name": "strict-transport-security",
                "value": "max-age=31536000; includeSubDomains"
            },
            {
                "name": "content-encoding",
                "value": "gzip"
            }
        ],
        "cookieHeaders": [],
        "data": "[{\"id\":null,\"result\":{\"success\":false},\"error_code\":1013,\"error\":\"JSON error: Syntax error, malformed JSON\"}]",
        "fileSize": 109
    }
]

Seems weird that Gripp would accept a line-separated list of items inside an array, but not simply comma-separated items…

Anyway, I don’t have time to dive into this deeper this week. To get the result you expect with your formula, try this:
{{replace(join(4.tags; ","); ","; ","{{newline}})}}

Cheers,
Henk

Giving a hard enter in the join solved my problem.

{{join(map(add(3.result.rows[].tags; 660); "id"); ",
")}}
1 Like