Solved

Remove [ ] from json response

  • 17 May 2023
  • 6 replies
  • 170 views

Userlevel 2
Badge +1

I am setting up a workflow to use the Google API to lock or unlock a Chrome device. I have most aspects working, but the trouble I am running into is that Google’s API returns things as an array of strings which is causing my next API call to be something like ‘[<device id>]’ instead of ‘<device id>’. Even if I add the array element I want in this case [0] my value is still wrapped in [ ]. Is there a simple way to strip the square brackets, or do I have to create expressions for each json array I want to use down the line?

icon

Best answer by rfrutiger 28 November 2023, 20:52

View original

6 replies

Userlevel 3
Badge +6

Facing the same issue. Hope someone has a solution for this. 

Userlevel 2
Badge +1

I ended up mapping index 0 of the array to a custom variable in my json parser for the api response from Google.

 

Userlevel 3
Badge +6

Seems not a 1-to-1 match to my issue but I was able to find a solution. 
Sharing it here so others can benefit from it. 


I wanted to capture the last added note in a change ticket, so in the JSON parser I added a new variable with [-1:]

 

This output was with “[]” and “”. To have that removed I just a liquid filter

 

{{P1.root.notes.notes_object.body.body_text_last |  replace: '[', '' |  replace: ']', '' |  replace: '"', '' | sanitze_html }}

Userlevel 7
Badge +16

You could also use the expression builder node to produce a substring that removes the unnecessary characters.

This allows the result of the expression to be used later on in other locations of the workflow as well.

Badge

I recently ran into this same issue with passing a requester id for a PUT api call and found that I had to change the index to 0 for the path variable and change the Type for the field to be number instead of array of numbers.

Userlevel 7
Badge +13

Seems not a 1-to-1 match to my issue but I was able to find a solution. 
Sharing it here so others can benefit from it. 


I wanted to capture the last added note in a change ticket, so in the JSON parser I added a new variable with [-1:]

 

This output was with “[]” and “”. To have that removed I just a liquid filter

 

{{P1.root.notes.notes_object.body.body_text_last |  replace: '[', '' |  replace: ']', '' |  replace: '"', '' | sanitze_html }}

Rather then using replace you can use  | remove: “]” | remove: “[” 

Reply