How to set a filter to null if key doesn't exist while adding a database record?
Hi,
I'm getting JSON data from an external source. However, the array of profile records that I'm getting isn't consistent. For example, some objects have the email key/value, some don't; some objects have the phone key/value, some don't. When I try mapping this to my Add Records step, I keep getting an error whenever the loop iterates over a profile where some key(s) don't exist. What approach should I use so that the corresponding fields in the DB are set to null if the key doesn't exist?
[ { "name": "John", "email": "john@email.com", "phone": "5551237890" }, "name": "Tracy", "phone": "5551237890" { "name": "Tim", "email": "tim@email.com" }, { "name": "Steve" } ]
I could do the keys filter for each profile object and then check using the in filter if email exists, if phone exists, etc. one check for each key that I expect but that seems to be extremely inefficient as every profile object has 50+ keys. I'm sure there's a better way to do this but I can't figure out how. Any help is much appreciated.
Thank you.
Best Answer
-
If you use a get filter instead of the dot notation, you can set a default value.
Answers
-
Yes, that's it. Thank you.
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