简体   繁体   中英

How can i add a new type or data type in json schema or adding conditional statements in JSON

Hi here im working on the application where i need to develop the ui based on the json and here my requirement is there are certain properties using which i can add in the json and from that i need to develop a table,dropdown etc. is there any possibility can i add these directly.

for ex

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://example.com/product.schema.json",
    "title": "Dynamic",
    "description": "ui from json",
    "type": "object",
    "properties": {
      "population": {
        "description": "The unique identifier for a product table",
        "type": "table"
      },
      "countries": {
        "description": "The unique identifier for a product table",
        "type": "dropdown"
      }
    }
  }

or if we mention type:string then how can we clearly mention in the json what is a table and and what is a dropdown or " how can i add if condition statements in json structure

What you want is an enum . This keyword will allow you do specify any number of discreet values (strings or otherwise) that are valid.

{ "enum": [ "red", "orange", ... ] }

Alternatively, if you want to support hex codes, you can use pattern to specify a regex that a string must satisfy.

{
  "type": "string",
  "pattern": "..."
}

You still need to specify the type as a string here because pattern only applies if the data is a string; it does nothing if the data isn't a string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM