Escaping JSON

Hello, searched on the forum and couldn’t a good topic/old post for my question.

I’m using a postman flow to collect data from our reporting system to monday.
I got it to work just fine.

My question is there another way to format create item column fields?
Doing it now needing to escape all " makes it hard to read and maintain.
Lucky I have only 5 columns to handla but if it comes up to 10+ columns it’s going to be hard to read and maintain.

any plans to change the API ?

Hello there @DanielSoderlund,

As of today, there are no plans of changing this in the near future.

With the structure as it is, there will be places in which you will need to escape outer quotes and there is no workaround to avoid it.

Let me know if you have any other questions!

Cheers,
Matias

Okay, thanks. I tried to read up on the GraphQL and I couldn’t find any way to convert to JSON.

I changed to so each column is on it’s own line. Makes it a bit easier to read and manage

mutation CreateItem($boardID: ID!, $itemName: String!) {
  create_item(
    board_id: $boardID,
    group_id: "{{group_id}}",
    item_name: $itemName,
    column_values: "{
        \"text\": \"{{Company}}\", 
        \"text2\": \"{{Project}}\", 
        \"time\": \"{{Time}}\", 
        \"date_1\": \"{{Date}}\", 
        \"text20\": \"{{ProjectID}}\", 
        \"people4\": \"{{consultant}}\",
        \"text7\":\"{{ActivityName}}\",
        \"text03\":\"{{OrgNo}}\"
        }"
  ) {
    id
  }
}```

Just use a regular object and use your languages facilities to convert to JSON. Why make this hard on yourself doing it by hand??? Here is a Javascript example

const values = JSON.stringify({
  text: companyName //these variables used as values come from your code elsewhere
  text2: projectName
  time: timeString
  date_1: dateString
})

Then just use the “values” string (which is JSON) as a GraphQL variable.

mutation CreateItem($boardID: ID!, $itemName: String!, $values: JSON!, $groupID: String) {
  create_item(
    board_id: $boardID,
    group_id: $groupID,
    item_name: $itemName,
    column_values: $values
  ) {
    id
  }
}

Now you don’t have to worry about escaping or quoting JSON right. create JSON using your language and then use that JSON string as a variable. This also solved all the mess you get when a value includes quotes and you can’t control if it does or not.

Stop substituting into the query string (that is all the query is, a string). There is zero need to put yourself through that misery. Create your JSON as actual JSON in code, then use a variable to use it in the mutation.

1 Like

The script didn’t work as pre-request script in postman, I guess I could tested some more with that but I tried this but it didn’t work. It looks about the same. It creates a array

mutation CreateItem($boardID: ID!, $itemName: String!, $values: JSON!, $groupID: String) {
  create_item(
    board_id: $boardID,
    group_id: $groupID,
    item_name: $itemName,
    column_values: $values
  ) {
    id
  }
}

GraphQL variables

{
  "boardID": "{{boardID}}",
  "itemName": "{{ItemName}}",
  "values":{ 
        "text": "{{Company}}",
        "text2": "{{projectName}}",
        "time": "{{timeString}}",
        "date_1": "{{dateString}}"
  }
}

You’re going to be only developing for postman? I expected you’re developing code that will run regularly and had access to a full javascript environment you were programming within (UI app feature, or node.js backend, or some other backend in another language.) and were just using postman for testing your queries.

I know a bit about postman’s pre-execution scripting but I haven’t built any of this in it before.

Built a POC in postman for a integration between our reporting system and Monday.
I got it working. Just that create item was a bit of hassle to setup.