Two methods to escape JSON in Make

Why not use the Transform to JSON module in the JSON app? Doesn’t that create properly escaped JSON text? And you can throw any object (array, collection, anything really) and it will create perfect JSON for you without needing to know anything about the incoming object.

No need for functions, no need for replace(), no need for Enterprise. It’s all there.

Here’s an array being passed into it with nested array:

Have a look at this scenario snippet. Copy and paste into a scenario
{
    "subflows": [
        {
            "flow": [
                {
                    "id": 1,
                    "module": "util:SetVariables",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "variables": [
                            {
                                "name": "textstring",
                                "value": "She said \"Hello, how are you?\" He said \"I'm good thanks.\" Let's meet at 5:00pm."
                            }
                        ],
                        "scope": "roundtrip"
                    },
                    "metadata": {
                        "designer": {
                            "x": 0,
                            "y": 0
                        },
                        "restore": {
                            "expect": {
                                "variables": {
                                    "items": [
                                        null
                                    ]
                                },
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "variables",
                                "type": "array",
                                "label": "Variables",
                                "spec": [
                                    {
                                        "name": "name",
                                        "label": "Variable name",
                                        "type": "text",
                                        "required": true
                                    },
                                    {
                                        "name": "value",
                                        "label": "Variable value",
                                        "type": "any"
                                    }
                                ]
                            },
                            {
                                "name": "scope",
                                "type": "select",
                                "label": "Variable lifetime",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "roundtrip",
                                        "execution"
                                    ]
                                }
                            }
                        ],
                        "interface": [
                            {
                                "name": "textstring",
                                "label": "textstring",
                                "type": "any"
                            }
                        ]
                    }
                },
                {
                    "id": 2,
                    "module": "json:TransformToJSON",
                    "version": 1,
                    "parameters": {
                        "space": ""
                    },
                    "mapper": {
                        "object": "{{1.textstring}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 300,
                            "y": 0,
                            "messages": [
                                {
                                    "category": "last",
                                    "severity": "warning",
                                    "message": "A transformer should not be the last module in the route."
                                }
                            ]
                        },
                        "restore": {
                            "parameters": {
                                "space": {
                                    "label": "Empty"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "space",
                                "type": "select",
                                "label": "Indentation",
                                "validate": {
                                    "enum": [
                                        "tab",
                                        "2",
                                        "4"
                                    ]
                                }
                            }
                        ],
                        "expect": [
                            {
                                "name": "object",
                                "type": "any",
                                "label": "Object"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}


Alex Sirota
Director of NewPath Consulting - we are :superhero: Make Heroes! :woman_superhero:t4:

:heart_on_fire: Check out my series of videos and scenario walkthroughs for Make Newbies :heart_on_fire:

My Solutions on Make Community

3 Likes