jdorn / json-editor

JSON Schema Based Editor
MIT License
5.8k stars 1.08k forks source link

How to make some array elements hidden #271

Open rmeshksar opened 9 years ago

rmeshksar commented 9 years ago

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.

jdorn commented 9 years ago

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
}
rmeshksar commented 9 years ago

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.

shreyasck commented 5 years ago

I also came across this issue can you suggest me if you have already found the answer for this?

thanks