json-editor
json-editor copied to clipboard
How to make some array elements hidden
Hi, I want to have an array in the json output and some of the elements of array should not be modified by editor. Is it possible in the schema for an array to have some fixed/predefined elements. User via editor can only add other elements to that array. Thanks.
In JSON schema, the items
keyword can be an array of schemas where each schema corresponds to a single array element. The additionalItems
keyword is used for all other array elements. You can use this in conjunction with enum
and minItems
to do what you want.
{
"type": "array",
"items": [
{
"type": "string",
"enum": ["first"]
}
],
"additionalItems": {
"type": "string"
},
"minItems": 1
}
Thanks for reply. It works, but I have some issues hiding those fixed elements. I created a schema here
As you can see "Filters" array has two fixed elements which is great, but is there any way to hide them in the editor. setting "hidden" property for the item did not work.
Also, how the rest of items can be managed in tabular format. When I set "format":"table" for the array, the json schema is not valid anymore. Thanks.
I also came across this issue can you suggest me if you have already found the answer for this?
thanks