Skip to main content
Solved

Remove [ ] from json response


rfrutiger
Apprentice
Forum|alt.badge.img+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?

Best answer by rfrutiger

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

 

View original
Did this topic help you find an answer to your question?

6 replies

Forum|alt.badge.img+6
  • Skilled Expert
  • 14 replies
  • November 28, 2023

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


rfrutiger
Apprentice
Forum|alt.badge.img+1
  • Author
  • Apprentice
  • 2 replies
  • Answer
  • November 28, 2023

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

 


Forum|alt.badge.img+6
  • Skilled Expert
  • 14 replies
  • November 29, 2023

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 }}


zachary.king
Skilled Expert
Forum|alt.badge.img+16
  • Skilled Expert
  • 951 replies
  • November 30, 2023

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.


Forum|alt.badge.img
  • Contributor
  • 4 replies
  • March 1, 2024

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.


Daniel Söderlund
Skilled Expert
Forum|alt.badge.img+14
RichardR wrote:

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