Covert Array into Object
Options
![Moises Amselem](https://us.v-cdn.net/6037124/user_avatars/4539444.jpg)
Moises Amselem
Member ✭
Hi, i receive an array of choices from an API, like the example below:
Tags: ["Marketplace","Cryptos","Real State"]
I would like to insert the response of the API i have called in a Object field. How i can do that?
Tags: ["Marketplace","Cryptos","Real State"]
I would like to insert the response of the API i have called in a Object field. How i can do that?
Comments
-
• Concept 1: Example of Tags as an Object
Tag {
"content_tag": "Marketplace",
"niche_tag": "Cryptos",
"category_tag: "Real Estate
}
• Concept 2: Example of Tags as an array of primitives or array of string values
Tags: ["Marketplace","Cryptos","Real State"]
Note: objects require key value pairs. For example
Tag {
"content_tag": "Marketplace",
"niche_tag": "Cryptos",
"category_tag: "Real Estate
}
The keys here are
• content_tag
• niche_tag
• category_tag
The values here are
• Marketplace
• Cryptos
• Real Estate
Conclusion
• BUT in your case the "tags" object from the API has NO SCHEMA, as it has NO KEYS. It's just a list of values.
Solution
• Therefore, from what you are saying, I would NOT suggest storing tags as an object
• I would (instead) suggest that in your database, you delete the "tags" object field and replace it with a "tags" text list field
• You are suppose to use "objects" in the database when you intend to store key_value pairs. For example
Detailed Example
• post_name --> pushed to "name" text column in database
• post_metadata: {"velocity": 100, "range": 22} --> pushed to "posts_metadata" object column in the database
BUT your case is more like
• post_name --> pushed to "name" text column in database
• post_tags: ["Marketplace","Cryptos","Real State"]--> pushed to "post_tags" object column in the database
Then, when you map your "api.response.results.posts.tags" to the "tags" text list field, the data will successfully go through -
Hi Umair, thanks a lot for your answer that was very clear. I changed the filed to text list and it worked perfectly!
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