String to JSON

Hi
I am new to this.
From another module before this, I have gotten a string with white spaces that looks like a JSON object.
The pipes is the start and end of the string.
| {
“tags”:[“travel tips”,“travel destinations”,“backpacking tips”]
}|

How do I make it into a proper JSON object like below
{
“tags”:[
“travel tips”,
“travel destinations”,
“backpacking tips”
]
}
I have tried using JSON module but it asking me to add datasource…it is a string from the output of a previous module.

Any help please?

Welcome to the Make community!

You can use the built-in function trim

e.g.:

trim(1.text)

For more information, see the function documentation in the Help Center.

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

@samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

To remove characters from the start and end of a string you’ll need to use the replace() string function to clean up the JSON first.

Then you can use the Parse JSON module inside of the JSON app to covert the JSON object into an output bundle that you can process with subsequent modules.

Here’s a functional example can try as the input to the Parse JSON module:

{{replace("|{""tags"":[""travel tips"",""travel destinations"",""backpacking tips""]}|"; "|"; emptystring)}}

To install the scenario blueprint (JSON) I made for you follow these steps:

  1. Expand the “Scenario Blueprint” by clicking on the arrow
  2. Copy the blueprint text into your clipboard using the copy button in the top-right of the code block (you can also select the text manually)
  3. Paste the text into a new scenario.

Your new scenario will now have all the modules I used to simulate an attempt at a solution to your question. You may need to confirm the configuration or reselect connections of each imported module in the scenario.

Scenario Blueprint
{
    "subflows": [
        {
            "flow": [
                {
                    "id": 1,
                    "module": "json:ParseJSON",
                    "version": 1,
                    "parameters": {
                        "type": ""
                    },
                    "mapper": {
                        "json": "{{replace(\"|{\"\"tags\"\":[\"\"travel tips\"\",\"\"travel destinations\"\",\"\"backpacking tips\"\"]}|\"; \"|\"; emptystring)}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 0,
                            "y": 0,
                            "messages": [
                                {
                                    "category": "last",
                                    "severity": "warning",
                                    "message": "A transformer should not be the last module in the route."
                                }
                            ]
                        },
                        "restore": {
                            "parameters": {
                                "type": {
                                    "label": "Choose a data structure"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "type",
                                "type": "udt",
                                "label": "Data structure"
                            }
                        ],
                        "expect": [
                            {
                                "name": "json",
                                "type": "text",
                                "label": "JSON string",
                                "required": true
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}


Alex Sirota

:heart_on_fire: Check out Make for Make Newbies Video Series :heart_on_fire:

My Solutions on Make Community

2 Likes

I don’t think trim() will work on removing non-space characters.

Hi Alex;

Thanks for the answer. You have given me a different view. This serves my alternate solution. I actually figure out the root was due to the upstream of flow not giving the correct structure.

1 Like