How to create elements such that it returns an array object

Hi,
I am creating repeatable group of fields using group element but the json am getting as an object rather than an array object. How to achieve that?
{
"Main": {
"formgroup": {
"type": "Group",
"config": {
"fields": [{
"id": "petname"
"type": "Text",
"config": {
"label": "petname",
"placeholder": "petname"
},
{"id": "email":
"type": "Text",
"config": {
"label": "email",
"placeholder": "email"
}
}
}],
"label": "formgroup"
}
}
}
}

Hi @poojapanwar27, the JSON that you shared above is the JSON definition of the Custom Type field. This is not what the Group field will return in the API.

Try publishing a document of this type with content inside your Group field and looking at the response from the API. You’ll see that the Group field returns an array :slight_smile:

Thanks Levi for the quick response. This is what I am getting now after publishing it. Its not giving me 2 objects in an array. Value is just 1 object and then we have petname and email. Its difficult to reiterate the value object as I want to make a dynamic form on UI. Also, Can i remove keynames like email and petname to make it generic.

“formgroup”: {
“type”: “Group”,
-“value”: [
-{
-“petname”: {
“type”: “Text”,
“value”: “cat”
},
-“email”: {
“type”: “Text”,
“value”: “a@a.com
}
}
]
}

This is the response from the API v1. Depending on the technology / SDK you’re using for your website you might be able to use the API v2 which gives the array directly for the Group field.
https://your-repo-name.prismic.io/api/v2

Which technology/framework are you using for your website?

It isn’t possible to remove the API IDs of the fields inside of the Group (“petname” and “email” in your case). If you want to remove these keynames, then that is something that you’ll need to do on your end after retrieving this from the Prismic API.

Thanks a lot Levi. Yes, this works well with API V2 for the results array. In your example, results is an array but I want to create an array within the result for the form groups which you have created for the description.

@poojapanwar27 I’m sorry, but I don’t understand what you’re looking for. Maybe you can clarify or use images to show what you’re hoping to do.

This issue has been closed due to inactivity.