json-editor icon indicating copy to clipboard operation
json-editor copied to clipboard

How to make some array elements hidden

Open rmeshksar opened this issue 9 years ago • 3 comments

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.

rmeshksar avatar Nov 02 '14 17:11 rmeshksar

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
}

jdorn avatar Nov 02 '14 18:11 jdorn

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.

rmeshksar avatar Nov 03 '14 02:11 rmeshksar

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

thanks

shreyasck avatar Oct 09 '18 10:10 shreyasck