Handling JSON array inputs
I have a list of id's being passed from my front end, and when I copy the inputs this is the format they are arriving in:
{"idList":"[4,5,6]","lessonID":"6","idListRef":"[1,2,3]"}
The result is empty, which is not right.
If I copy and past how it is received into the run and debug and remove the "" around the [], like this:
{"idList":[4,5,6],"lessonID":"6","idListRef":[1,2,3]} the response the debugger gives is what is expected.
To get the response I am performing a Query All Records from the table where:
auth.id = db.user_id
and where db.field_id in idListRef
I don't believe the issue is in the query because it works if I remove the "", but I can not figure out why this is or how to resolve this issue. I have tried passing the data several different ways but can not figure it out. Any help in the right direction would be greatly appreciated!
Best Answer
-
Hi, @Chris Coleman. First off thank you for your quick response to my post. The more and more I use this resource I am amazed at the speed the Xano team responds to assist and resolve issues. The front end I am using is Webflow, but I am using custom javascript to handle API requests, so I don't think there would be a setting adjustment to make. While I am sure the solution you provided would have worked, I was stubborn to handle the issue on the frontend code. I wanted to share my solution if anyone else stumbles into the same issue.
I was sending the request as a GET request and passing the parameters in the URL, this was forcing me to stringify the array prior to sending. I changed the request to a POST request, allowing me to send the parameters in the body of the request solving my issue.
Again, thank you for your quick response!
Answers
-
Hi, @System8. Looks like your front-end is sending the array as a text string. I would first see if there is an adjustment you can make on your front-end to send the array properly (without quotes).
If this is for some reason not an option, you can fix this in Xano by creating a new variable with the contents of the array being sent as text, and apply a couple of filters to transform it into an array.
This would start with two remove filters, to pull out the [ and ].
The second filter would be split, with a , separator. This will turn the remainder of the text string into a true array that you can work with.
-
Hi @System8,
Glad to hear you've had a good an experience with our support team. 🙌 Thank you for sharing the solution that worked to solve this issue!
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback