Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is a JSON Schema and why is it useful? How do I create/use a JSON Schema? #1

Open
nelsonic opened this issue Oct 21, 2016 · 3 comments

Comments

@nelsonic
Copy link
Member

Answer the question that is obviously on everyone's mind... 😉

@sohilpandya
Copy link
Member

sohilpandya commented Oct 31, 2016

JSON SCHEMA

JSON schema is a powerful tool for validating the structure of JSON data.

But what does it actually mean in layman's term?

What is JSON?

  • Javascript Object Notation
  • store information.
  • Uses following data structures
    • Object, Array, Number, String, Boolean, Null
{  
    “key1”: “value1”,
    “key2”: “value2”,
}

What is a JSON schema?

  • used to define the structure of the JSON Object.
  • useful tool for defining what type of data structure you want to return.

E.G.
When a user submits a form, you want to validate all the information they may have entered.

Expected Object:

{
    “type”: “object”,
    “properties”: {
        “first name”: { “type”: “string” },
        “last name”: { “type”: “string” },
        “age” : { “type”:  “number” }
    }
}

Now if the submit a the following object: ✖️ It would fail the validation that we have put in place.

{
    “first name”:”Mickey”,
    “last name”: “Mouse”
}

But, the following object: ✔️ It would pass the validation.

{
    “first name”:”Mickey”,
    “last name”: “Mouse”,
    “age”: 100
}

There we have our first JSON Schema for validation purposes! 😄

@deadcoder0904
Copy link

@sohilpandya edit "first name" to "last name" in the Expected Object as u have written it twice 😄

@sohilpandya
Copy link
Member

sohilpandya commented Oct 31, 2016

Thanks! @deadcoder0904 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants