#community-help

Creating JSON Collection with Object Array

TLDR suraj asked how to create a JSON collection with an object array. Kishore Nallan advised adding addresses and letting internal fields be auto-detected.

Powered by Struct AI
8
5mo
Solved
Join the chat
Apr 06, 2023 (5 months ago)
suraj
Photo of md5-396118c791d531ff7af8cd473d5b26ff
suraj
04:23 AM
How do I create below collection

{
"name":"abc",
"addresses":[{
"pincode":123,
"street":"abc",
"type":"home"
},{
"pincode":123,
"street":"abc",
"type":"office"
}
]

}
04:26
suraj
04:26 AM
Can I use something like this
04:26
suraj
04:26 AM
fields.add(new Field().name("addresses").type(FieldTypes.OBJECT_ARRAY));
fields.add(new Field().name("addresses.pincode").type(FieldTypes.STRING));
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
05:38 AM
You can just add addresses alone. The internal fields will be auto detected.
suraj
Photo of md5-396118c791d531ff7af8cd473d5b26ff
suraj
05:57 AM
so there will be no code for internal field. like no java code to adding field
05:57
suraj
05:57 AM
just this line of code
Field().name("addresses").type(FieldTypes.OBJECT_ARRAY));
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
05:59 AM
Yes
suraj
Photo of md5-396118c791d531ff7af8cd473d5b26ff
suraj
06:03 AM
Yes got it.. Thanks Kishor!!