2

My Json Schema :

{
   "type" : "object" ,
   "properties" : {
      "status" : {
        "type" : "string" ,
        "pattern" : "(OPEN|CLOSE)/i"
      } ,
      "phone" : {
        "type" : "string" ,
        "pattern" : "[0-9a-zA-Z_\\s]+"
    }
  }
}

My Input :

{
   "status" : "open" ,
   "phone" : "9080245591"
}

I try to check the input using json schema.But json validator throw the following error. pattern value is wrong.So how to solve it. and it throw String 'open' does not match regex pattern '(OPEN|CLOSE)/i'. this error also

4
  • please post your code also Commented Jul 12, 2018 at 9:52
  • i am use online validator. it also throw error.My validator tool is jsonschemavalidator.net Commented Jul 12, 2018 at 9:55
  • As others, I cannpt make sense of your regex for phone. Please use debuggex.com and set type to javascript. Commented Jul 12, 2018 at 10:38
  • my phone regex pattern allowed any country phone number. Some Country take his language letter.So wrote this Commented Jul 12, 2018 at 10:45

1 Answer 1

5

I found two issues in your schema:

  1. Currently the specification does not allow you to specify flags like /i for case insensitive matching. You can address this by adding the flag to the expression itself (?i).
  2. You're specifying an InBasicLatin character set. That should bre IsBasicLatin.

The fixed schema:

{
   "type" : "object" ,
   "properties" : {
      "status" : {
        "type" : "string" ,
        "pattern" : "^(?i)(OPEN|CLOSE)$"
      } ,
      "phone" : {
        "type" : "string" ,
        "pattern" : "[0-9a-zA-Z_\\-\\.\\$@\\?\\,\\:\\'\\/\\!\\P{IsBasicLatin}\\s]+"
    }
  }
}

Note: I can't make sense of your pattern for phone, so I just fixed the error but otherwise didn't touch it.

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

4 Comments

But your status property pattern is wrong. It work like endswith open or close
My pattern is neither wrong nor right because you didn't provide any specifications of what input should and shouldn't be allowed. I just fixed the error in your pattern.
oh sorry Robby Cornelissen. status value is allowed only open | close.So how to i am fix it
Updated my answer. I think you're gonna want to take a long hard look at your phone pattern as well.

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.