Need help to store nested json format into database and get the correct output

I’m using leaflet.js and want to store the following json format into database. I’m particularly clueless on how to input the sub object with array into database and later output it into this exact structure. Any help is much appreciated.

                "type": "Feature",
                "geometry": {
                    "type": "LineString",
                    "coordinates": [
                        [-105.0008225440979, 39.751891803969535],
                        [-104.99820470809937, 39.74979664004068]
                "properties": {
                    "popupContent": "This is a free bus line that will take you across downtown.",
                    "underConstruction": true
                "id": 2

If you’re using NodeJS, you can create this JSON structure inside a Set Value step, and store in the DB by using var1.toJSON().
Then, when you retrieve it, just use query1.col1.parseJSON() in a Set Value and return that.

Ref: How best to unwrap a stringified JSON

Thanks for the suggestion sid. I’m not quite sure exactly how to implement your suggestion though but I’ve stored the json structure into db and use set value. I think it can automatically detect the value as json. The problem with serverconnect is that the action file is in json format so it’s quite impossible to have json structure as the value without using escape.

My main objective is so that I can parse the value into client side with such structure.

So insert is working for you then. That’s good.

When you retrieve it from the DB in a server action/API, the response in network tab should look like an escaped JSON string.
You have two options here:

  1. If the query is returning a single row, you can use a set value in server action to do something like: query1.col1.parseJSON(), then use that set value in the client side.
  2. You can create a custom client side formatter on the client side to convert the JSON string to JSON object.
1 Like

Alright, will try it out when I get there. I think JSON.parse() will do the job on the client side. I see where I’m heading now. Thanks for the insight.