0

JSON contains run time key and value pairs

{
  "user_id" : 2
  "applicationName": "RetailPos",
  "permissions": {

  "Purchase": [
    "Access",
    "Create",
    "Delete",
    "Modify"
   ],
  "Sales": [
    "Access",
    "Create",
    "Delete",
    "Modify"
   ]
  },
 "group": "Admin Group"
}

consider the above sample, here Purchase and Sales are Targets and values Access,Create... are operations. Here both Targets and operations are run time values.

In this JSON Schema Validation couldnt find enough samples to create required schema.

{
"required": true,
"$schema": "http://json-schema.org/draft-03/schema",
"type": "object",
"properties": {
     "user_id": {
        "type": "number",
        "required": true
    },
     "application_name": {
      "type":"string",
      "required":true
    },

    //Permission schema

    "group" : {
      "type" :"string",
      "required":true
    }
  }
}

Any documentation or related samples would be useful.

1 Answer 1

3

You could use the "additionalProperties" keyword. For example:

{
  "$schema": "http://json-schema.org/draft-03/schema",
  "type": "object",
  "properties": {
     "user_id": {
        "type": "number",
        "required": true
    },
     "applicationName": {
      "type":"string",
      "required":true
    },   
    "permissions": {
      "additionalProperties": {
        "type": "array",
        "items": {
          "type": "string",
          "enum": ["Access", "Create", "Delete", "Modify"]
        },
       }
     },

    "group" : {
      "type" :"string",
      "required":true
    }
  }
}

More info here and here

Sign up to request clarification or add additional context in comments.

2 Comments

additionalProperties could be any but here there is a specific definition
@vels4j is something missing ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.