I aim to create a condition for additional properties in JSONschema that handle any schema (all the types such as object|array|Boolean|string|number|null) and if the type is a string then it could be a normal string OR a regular expression as follows: (a|b(\\ \\<[a-z]|(-?\d+)\\,[09]\\> ) that denote the string ( "a|b(<anytype,number>)" ). The following code shows errors of invalid schema:

 { "type" : "object",
 "properties": { "firstname":{"type": "string},"lastname":{"type": "string} },
 "required": ["firstname","lastname"],
 "additionalproperties":{"type":["integer", "number", "null", 
 "boolean","object", "array"],"pattern":^(string|(a|b(\\ \\<[a-z]|(-?\d+)\\)$, 

The syntax highlighting starts to show your error. You are missing a quote after string for your firstname property:

firstname":{"type": "string},

You do the same thing after `lastname' as well:

"lastname":{"type": "string}

And your regex is completely missing a starting quote:

"pattern":^(string|(a|b(\\ \\<[a-z]|(-?\d+)\\)$,[09]\\>)))"

You also have an invalid regex as it an extra parenthesis and needs an extra slash before \d+:

^(string|(a|b(\\ \\<[a-z]|(-?\\d+)\\)$,[09]\\>))

And finally also have an extra closing }

    "type": "object",
    "properties": {
        "firstname": {
            "type": "string"
        "lastname": {
            "type": "string"
    "required": ["firstname", "lastname"],
    "additionalproperties": {
        "type": ["integer", "number", "null",
            "boolean", "object", "array"
        "pattern": "^(string|(a|b(\\ \\<[a-z]|(-?\\d+)\\)$,[09]\\>))"

A lot of this, the regex being the only exception, was easily solvable through basic troubleshooting. The first thing to do is format your code, in this case your JSON string. It is easier to read and then spot errors. Take your time and review your work. You'll go faster but moving slower.

  • thank you for your comment. Is there a pattern to describe arrays and objects,i would like to add to the pattern because in the previous one i have only mentioned string and number like <object|array|Boolean|string|number|null , number > ?
    – twesky
    Jun 1 '19 at 12:31
  • is ts possible to solve it ?
    – twesky
    Jun 1 '19 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.