Giter VIP home page Giter VIP logo

understanding-json-schema's Introduction


πŸ“Œ Deprecation Notice πŸ“Œ

This repository is now deprecated. To contribute to the JSON Schema docs please use the new repository ➑️ https://github.com/json-schema-org/website.


understanding-json-schema

Contributor Covenant Project Status: Active – The project has reached a stable, usable state and is being actively developed. Financial Contributors on Open Collective

Build Status

A website aiming to provide more accessible documentation for JSON schema.

http://json-schema.org/understanding-json-schema/index.html

Build locally

You can build and serve the website locally using docker. Running docker-compose up will start the server on http://localhost:8000

understanding-json-schema's People

Contributors

andersk avatar bdronneau avatar benjagm avatar brannerchinese avatar btubbs avatar cgore avatar embray avatar forevermatt avatar fulldecent avatar goldaxe avatar hongwei1 avatar jacquev6 avatar jcttrll avatar jdesrosiers avatar koenrh avatar krystof-k avatar mdboom avatar micshar92 avatar mkobit avatar oliworx avatar pfridberg avatar ralfhandl avatar ravicodelabs avatar relequestual avatar salim-b avatar samestep avatar scottj97 avatar tsamb avatar whathecode avatar wyfo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

understanding-json-schema's Issues

Draft-6 is coming!

Hey Team!

Just wanted to let you know we're getting pretty close to finishing and releasing draft-6.
I don't know if you plan to continue maintaining this resource, but it's useful to me and many others.

Cheers

Note on Python dicts

It would be nice to note in the book that there is one very important distinction between JSON objects and Python dicts - JSON objects keep the order of keywords, while order of Python dicts' keys is undefined (simply put, it can be random order, different every time we try to print it out... depends on implementation).

Newbie could be surprised by Python's behavior. Also, note on existence of collections.OrderedDict could help.

PHP examples?

Would there be any interest in having PHP code equivalents added?

I wouldn't mind adding those if there is interested in accepting such a PR...

Update for Draft 7

Once support for Draft 7 is in Julian/jsonschema, work can start on this in earnest.

Properties as Property not working

Hi, I would like to something like this:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "$schema": {
      "type": "string"
    },
    "title": {
      "type": "string"
    },
    "properties": {
      "type": "object",
      "enum": "metadata"
    },
    "required": {
      "type": "array",
      "items": {
        "metadata": "string"
      }
    }
  }
}

but this part is not working well:

"properties": {
      "type": "object",
      "enum": "metadata"
 },

Is possible to do this? or is estrictamente prohibido to use those built schema words like: "required", "enum", "properties" as a property inside "properties"?.
Thanks in advance for helping me to understand this part πŸ˜„

Have not mentioned `id`

I found that id was never mentioned in this book. Actually I have difficulties in understanding that part in spec during implementation of a validator. Is there a plan for covering it?

By the way, this book is very useful for me to learn json schema in short time. Thank you.

Include simple example of `"additionalProperties": false`

The new learning section looks great! Super props to @retrosight!

One common question is around additional properties not defined in the properties schema still passing validation.
I think we've been pretty clear that key words ADD constraints, but I still expect this is sometimes missed.

I feel a small section at the end of the getting started section could address the use case for "additionalProperties": false and show the simplest of examples.

I think sometimes we (including myself) forget that reading RFCs is hard. =]

Per page/section table of content (TOC)

It would be nice to have a local table of contents on each page on the web site. Now, if you aren't sure which subsection you are looking for you have to scroll down the page looking out for headings, and it is very easy to miss headings that way. If there were a TOC (list (with sublists) with links) it would be much easier to see what is found on the page.

Provide links for older version (draft-4, ...)

Is That possible to provide a link to Jekyll some branches of this repo ?
Something like pointing over a branche feature/draft-4 ? :

https://draft-4.json-schema.org/understanding-json-schema/

But maybe this issue should be more related to json-schema.org ?
In any case, I don't see any version tag or branches to do such a fix.

Thanks, great job for this doc anyway.

Rework the section regarding $id and $ref

The example of how to use $id with $ref is not how we would like people to do things.

https://json-schema.org/understanding-json-schema/structuring.html#using-id-with-ref

We should rework this to show the intended general use case, where you reference another file by it's $id, including relative URI resolutions.

It's possibly worth noting that you can use an $id in a subschema, but it's not advised because it makes things more complex.

Additionally, is the statement about no support for this true in terms of the python library?

@Julian ?

[Question] Tuple validation with enum in the first

In the following schema,

{ "type": "array",
  "items": [
{ "type": "number" },
{ "type": "string" },
{ "type": "string",
  "enum": ["Street", "Avenue", "Boulevard"] },
{ "type": "string" } ] }

I'm trying to validate this: [1600, "Pennsylvania", "Avenue", "NW"]

Now, the documentation explains that it's okay to leave out items. What happens if I leave out the third item "Avenue". It would not validate the JSON because "NW" is not enumerated in the schema? This would especially get more interesting if the first item is enum . Like so:

{ "type":"array",
  "items": [
  { "type": "string",
  "enum": [ "Alice", "Bob", "Eve", "Mallory" ] },
  { "type": "string"} ]
}

Is there a way I can work around this problem?

`$schema` description is inaccurate

schema.rst includes this sentence:

The $schema keyword is used to declare that a JSON fragment is actually a piece of JSON Schema.

This is incorrect; JSON Schema doesn't place any restrictions on JSON documents, so it's perfectly valid for a non-schema JSON document to include a $schema key. (The meaning of that key would be specific to the writers/readers of that particular document.)

Conversely, it's also not the case that a piece of JSON Schema will have a $schema key; its presence in root schemas is only a SHOULD, and it MUST NOT appear in sub-schemas (which are, of course, JSON fragments that are actually pieces of JSON Schema).

(#50 is related to this, but given the age of that issue I was asked to open a new one. I was also asked to note that this should be a post-draft-8 discussion.)

Include `additionalItems` schema example

Michael Zub wrote:

Thank you for great "Understanding JSON Schema" site and book. It is very helpful and easy to understand and should be recommended to everyone working with JSON Schema.

As a reader I have a minor remark on "additionalItems" keyword description. On page 26 you have wrote:

"The additionalItems keyword controls whether it’s valid to have additional items in the array beyond what is defined in the schema. Here, we’ll reuse the example schema above, but set additionalItems to false, which has the effect of disallowing extra items in the array."

According to this one can assume that "additionalItems" can be only boolean flag, but there is a case when "additionalItems" can be schema that describes additional array items (very similar as "additionalProperties" works).
As example, schema {"items":[{}],"additionalItems":{"type":"integer"}} won't validate next JSON: [null,2,3,"foo"]. If this data is put into the validator (for example http://json-schema-validator.herokuapp.com/index.jsp) the error will be "instance type (string) does not match any allowed primitive type (allowed: ["integer"])".

The example from above is taken from JSON Schema Test Suite - https://github.com/json-schema/JSON-Schema-Test-Suite

I think it will be great if similar case is added to your book.

Regards,
Micheal Zub

PDF does not distinguish between good and bad examples

Greetings,
For example, on page 12 of the PDF, it shows:
{ "type": ["number", "string"] }
and then lists a few examples.

    42
    "Life, the universe, and everything"
    ["Life", "the universe", "and everything"]

They are not distinguished as 'pass' or 'fail', but on the original page you can see that the third example is supposed to be bad.

Some form of distinguishing marks on the PDF would make it significantly more useful, as right now it is more confusing than helpful.

-- Morgan

Make epub version work

The epub version currently puts a header and footer at the beginning and end of every chapter. There are probably other issues as well.

Allow "null" as value for numbers or the like

Hi there,

thanks for the great work--please keep it up :)

I was wondering whether you've thought about providing an option to allow null values for other types. I'm thinking about something like this (pseudo code):

{
  "type": "number",
  "minimum": 0,
  "nullAllowed": true
}

This would then validate true against the following examples, whereas currently the second example would fail:

  • { "foo": 13 }
  • { "foo": null }

Thanks,
Mario

Set "required" in property definition

I didn't find information on the document. So I don't know whether it is exists.

Current usage for "required" command:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "required": [
        "name"
    ],
    "properties": {
        "name": {
            "type": "string"
        }
    }
}

When I want to remove the property "name", I should always remember removing "name" from "required" array.
It will be helpful if I can define "required" in the definition of properties. For example:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
        "name": {
            "type": "string",
            "isRequired": true
        }
    }
}

Please let me know if there are reasons we can not do like this.

"Integral" doesn't mean what you think it does.

The following line is in numeric.rst:

The integer type is used for integral numbers.

While that sounds good, there isn't really any such thing as an integral number. When applied to numbers, the term "integral" generally refers to the area under the curve of a graphed function.

To be correct (although redundant), the line should read, "The integer type is used for integers".

EDIT: Wait, never mind. Definition 5 of integral from dictionary.reference.com:

Arithmetic. pertaining to or being an integer; not fractional.

header navigation error

Hi there!

I'm reading the online book(thanks you guys for this!), and found a small bug in Generic Keywords page.
Navigation menu shows null as prev page, maybe this is an error in sphynx? I dont have any experience with sphynx-doc, so im still taking a look to see if I can fix this...
Maybe someone with more knowledgement in this subject can help fixing this (must be a easy task, I think).

ref image:

Update the help

Tyler Desjardins mentions that we should consider moving emails from help[at]stsci.edu to point to the web portal where possible and appropriate. For HST (or any non-JWST), it is https://hsthelp.stsci.edu . For JWST, it is https://jwsthelp.stsci.edu . Please update info in setup.py, setup.cfg, documentation, etc as appropriate.

Please close this issue if it is irrelevant to your repository. This is an automated issue. If this is opened in error, please let pllim know!

xref spacetelescope/hstcal#317

HiDPI support

The octopus on the front page and the accept/reject icons in the text are not retina-display compliant. That should probably be fixed.

$schema

Hello, firstly thanks for writing this guide, very useful! My issue relates to the use of the $schema keyword/property, as I understand it, this is a string pointing to the schema for the document in question. Hence why schema documents point to "http://json-schema.org/draft-04/schema". In your guide you say that:

The $schema keyword is used to declare that a JSON fragment is actually a piece of JSON Schema

This is not my understanding; it doesn't declare that the containing fragment is a schema, but that it conforms to the particular schema which is given by the value of the $schema property. So JSON schemas should point to the above location because that schema defines how schemas should be laid out. Whereas JSON documents conforming to a schema you've created should set the $schema property to point to the schema that they have created. I've been a bit confused about this so I am happy to be corrected!

Thanks again

Mark

Add documentation on language specific implementation libraries

It can't hurt to add a chapter listing and describing how to actually use some JSON Schema implementations. While I don't think it should serve as a full replacement for those projects' own documentation it can't hurt to point to the best libraries available for a given language and some basic examples of how to use them.

I'll assign myself this since it's my idea.

Simple Next Page Button

I loved this quick tutorial. I would add a way to let me go from one page to the next without having to go back to the main menu. That small change would make a huge difference

patternProperties and additionalProperties

http://spacetelescope.github.io/understanding-json-schema/reference/object.html#pattern-properties

patternProperties only takes effect if additionalProperties is set to false.

This isn't quite right.

What actually happens is that if a property matches anything in patternProperties then additionalProperties does not apply to it. So I can have something like:

{
    "type": "object",
    "patternProperties": {
        "^[0-9]+$": {"type": "integer"}
    },
    "additionalProperties": {"type": "string"}
}

This says that any key made entirely of decimal digits must have an integer value. Anything else must be a string.

Valid: {"0123": 4567, "foo": "bar"}
Invalid: {"foo": 1234}

Your examples in the guide are still valid - if additionalProperties is false, then only properties from properties/patternProperties are allowed. However, this is not the only situation where patternProperties can be used.

Using "allOf" with "additionalProperties":false

Hello
Here is sample schema from tutorial :

{
"$schema": "http://json-schema.org/draft-04/schema#",

"definitions": {
"address": {
"type": "object",
"properties": {
"street_address": { "type": "string" },
"city": { "type": "string" },
"state": { "type": "string" }
},
"required": ["street_address", "city", "state"]
}
},

"type": "object",

"properties": {
"billing_address": { "$ref": "#/definitions/address" },
"shipping_address": {
"allOf": [
{ "$ref": "#/definitions/address" },
{ "properties":
{ "type": { "enum": [ "residential", "business" ] } },
"required": ["type"]
}
]
}

}
}

Here is valid instance:
{
"shipping_address": {
"street_address": "1600 Pennsylvania Avenue NW",
"city": "Washington",
"state": "DC",
"type": "business"
}
}

I need to limit used fields for shipping_address as following :

"shipping_address": {
"allOf": [
{ "$ref": "#/definitions/address" },
{ "properties":
{ "type": { "enum": [ "residential", "business" ] } },
"required": ["type"]
}
],
"additionalProperties":false
}

While checking with validator , I got following error :

[ {
"level" : "error",
"schema" : {
"loadingURI" : "#",
"pointer" : "/properties/shipping_address"
},
"instance" : {
"pointer" : "/shipping_address"
},
"domain" : "validation",
"keyword" : "additionalProperties",
"message" : "additional properties are not allowed",
"unwanted" : [ "city", "state", "street_address", "type" ]
} ]

The question - how should I limit fields of shipping_address in the sample above ?
Thanks in advance

Since we already have a new 2019-09 draft, would it be the case to create a draft-07 branch in this repository? Or right before adding info specific to 2019-09?

Right now, we have this note in the documentation:

Note: This book describes JSON Schema draft 7. Earlier versions of JSON Schema are not completely compatible with the format described here, but for the most part, those differences are noted in the text.

One day, "Understanding json schema" will have support for 2019-09 specification. Since a lot of people will be using older drafts that still need to have reference to older documentation, it would be nice to have a branch or a tag of this repository while in draft 7 for reference. If you don't want the overhead of doing this right now, please consider adding this right before adding docs about the new 2019-09 draft.

Little icons in example boxes cut off in Firefox 24

See this screenshot:
untitled

The little checkbox, gear, etc. icons in the example boxes get cropped in particular in single-line boxes. which I find weirdly distracting (they don't bother me otherwise). I haven't tried this on any other browser yet so I don't know if it's a browser-specific issue.

This could be resolved by either increasing the inner padding on those boxes or making the icons a bit smaller (I think I would prefer the latter).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.