GeoJSON schema

3,553 views
Skip to first unread message

Tore Nauta

unread,
Jan 22, 2013, 5:36:01 PM1/22/13
to json-...@googlegroups.com
Does anyone know of a JSON Schema that describes the GeoJSON spec?


Tore

Francis Galiegue

unread,
Jan 22, 2013, 5:47:08 PM1/22/13
to json-...@googlegroups.com
No, but it can be written.

I'll have a go at it. I'll post two links when I'm done with it: one
conforming to draft v3, another for v4.

--
Francis Galiegue, fgal...@gmail.com
Try out your JSON Schemas: http://json-schema-validator.herokuapp.com

Francis Galiegue

unread,
Jan 22, 2013, 6:15:29 PM1/22/13
to json-...@googlegroups.com
On Tue, Jan 22, 2013 at 11:47 PM, Francis Galiegue <fgal...@gmail.com> wrote:
> On Tue, Jan 22, 2013 at 11:36 PM, Tore Nauta <tore....@gmail.com> wrote:
>> Does anyone know of a JSON Schema that describes the GeoJSON spec?
>>
>> http://geojson.org/geojson-spec.html
>>
>> Tore
>>
>
> No, but it can be written.
>
> I'll have a go at it. I'll post two links when I'm done with it: one
> conforming to draft v3, another for v4.
>

It turns out to be a little more complicated than what I anticipated
at first, but not undoable ;)

As an exercise, dive into the spec by yourself: there is that notion
of point, which is well defined. Do you think you can create a schema
for just that?

See the site in my signature: you can test your schemas and data there!

Tore Nauta

unread,
Jan 22, 2013, 6:32:06 PM1/22/13
to json-...@googlegroups.com
Thanks Francis,

That will indeed be a good exercise for getting acquainted with both GeoJSON and JSON-Schema. Let me give it a try.

Tore

Francis Galiegue

unread,
Jan 23, 2013, 9:30:07 AM1/23/13
to json-...@googlegroups.com
On Wed, Jan 23, 2013 at 12:32 AM, Tore Nauta <tore....@gmail.com> wrote:
> Thanks Francis,
>
> That will indeed be a good exercise for getting acquainted with both GeoJSON
> and JSON-Schema. Let me give it a try.
>
> Tore
>

Here is a schema for a geometry entry:

https://gist.github.com/4606371

Now I'll test it ;)

Next is the geometry collection and features.

Francis Galiegue

unread,
Jan 23, 2013, 10:34:43 AM1/23/13
to json-...@googlegroups.com
And here is another schema, describing all objects:

https://gist.github.com/4608239

Note: crs and bbox are lacking.

Tore Nauta

unread,
Jan 23, 2013, 10:36:09 AM1/23/13
to json-...@googlegroups.com
Cool! I also started to look at it and had the following so far.

I had some problems with the validator. When I was trying different schemas it seemed to remember (or cache) some of the previous sub-schemas I had used. Changing the sub-schema definition did not seem to take effect unless I gave the sub-schema a different name, like multilinstring1 instead of multilinestring. Very confusing for a newbie like me :)

Is that something you've encountered as well?

Tore



{
    "title": "GeoJSON",
    "description": "A GeoJSON object",
    "type": "object",
    "anyOf": [
        { "$ref": "#/definitions/point" },
        { "$ref": "#/definitions/multipoint" },
        { "$ref": "#/definitions/linestring" },
        { "$ref": "#/definitions/multilinestring" }
    ],
    "definitions": {
        "multilinestring": {
            "description": "A GeoJSON MultiLineString",
            "type": "object",
            "required": ["type", "coordinates"],
            "properties": {
                "type": { "enum": ["MultiLineString"] },
                "coordinates": { 
                    "type": "array",
                    "items":  { "$ref": "#/definitions/linestring/properties/coordinates" }
                }
            }
        },
        "linestring": {
            "description": "A GeoJSON LineString",
            "type": "object",
            "required": ["type", "coordinates"],
            "properties": {
                "type": { "enum": ["LineString"] },
                "coordinates": { 
                    "type": "array",
                    "minItems": 2,
                    "items": { "$ref": "#/definitions/position" }
                }
            }
        },
        "multipoint": {
            "description": "A GeoJSON MultiPoint",
            "type": "object",
            "required": ["type", "coordinates"],
            "properties": {
                "type": { "enum": ["MultiPoint"] },
                "coordinates": { 
                    "type": "array",
                    "items": { "$ref": "#/definitions/position" }
                }
            }
        },
        "point": {
            "description": "A GeoJSON Point",
            "type": "object",
            "required": ["type", "coordinates"],
            "properties": {
                "type": { "enum": ["Point"] },
                "coordinates": { "$ref": "#/definitions/position" }
            }
        },
        "position": {
            "description": "A GeoJSON Position",
            "type": "array",
            "minItems": 2,
            "items": { "type": "number" }

Francis Galiegue

unread,
Jan 23, 2013, 10:42:55 AM1/23/13
to json-...@googlegroups.com
On Wed, Jan 23, 2013 at 4:36 PM, Tore Nauta <tore....@gmail.com> wrote:
> Cool! I also started to look at it and had the following so far.
>
> I had some problems with the validator. When I was trying different schemas
> it seemed to remember (or cache) some of the previous sub-schemas I had
> used. Changing the sub-schema definition did not seem to take effect unless
> I gave the sub-schema a different name, like multilinstring1 instead of
> multilinestring. Very confusing for a newbie like me :)
>

If you selected to "use id", then this is normal. The validator is
shared by everybody, so the first to come wins in this case ;) I could
recreate a validator each time but that'd be quite expensive. I should
probably have a go at implementing sessions... And serialize whatever
schemas the user has entered.

Gee. Big job, that. I need to configure a storage on Heroku, etc... Of
course, you have the option to clone the app and run it locally, it's
quite easy: all you need installed is a JDK 6+ (OpenJDK works fine)
and Maven 2.x or 3.0.4+.

Tore Nauta

unread,
Jan 23, 2013, 11:49:33 AM1/23/13
to json-...@googlegroups.com
This looks great! Thanks a lot.

Tore

Tore Nauta

unread,
Jan 23, 2013, 11:58:48 AM1/23/13
to json-...@googlegroups.com
The online validator is very useful!

For what it's worth, I did not select the "use id".

Another question/feedback regarding the validator. I started off using the "oneOf" keyword, but if data was not valid I would get the basic message: "instance does not match exactly one schema". It would not specify why the sub-schemas didn't validate.

However, when I used "anyOf", it would give me an explanation for each sub-schema why the data is not valid.

Thanks again,
Tore

Francis Galiegue

unread,
Jan 23, 2013, 5:53:09 PM1/23/13
to json-...@googlegroups.com
OK, full sample of GeoJSON schemas, with bbox, crs and everything:

https://github.com/fge/json-schema-validator-demo/tree/master/src/main/resources/geojson

On Wed, Jan 23, 2013 at 5:58 PM, Tore Nauta <tore....@gmail.com> wrote:
> The online validator is very useful!
>

Thanks ;)

[...]
> Another question/feedback regarding the validator. I started off using the
> "oneOf" keyword, but if data was not valid I would get the basic message:
> "instance does not match exactly one schema". It would not specify why the
> sub-schemas didn't validate.
>
> However, when I used "anyOf", it would give me an explanation for each
> sub-schema why the data is not valid.
>

Yes, this is a defect in the logs currently. You are one of the first
ones apart from me to notice this. Given its intended first use, this
library would still return false on "report.isSuccess()", in fact,
most users of the library don't care for error messages, just that the
data is invalid.

I am working on fixing that, but it will take some work.

Tore Nauta

unread,
Jan 23, 2013, 6:33:21 PM1/23/13
to json-...@googlegroups.com
On Wednesday, January 23, 2013 2:53:09 PM UTC-8, fge wrote:
OK, full sample of GeoJSON schemas, with bbox, crs and everything:

https://github.com/fge/json-schema-validator-demo/tree/master/src/main/resources/geojson


Beautiful!

Francis Galiegue

unread,
Feb 28, 2013, 6:12:15 AM2/28/13
to json-...@googlegroups.com
On Thu, Feb 28, 2013 at 10:25 AM, <krzysztof...@gmail.com> wrote:
> On Feb 12, 2013 moved without notice to new home:
>
> https://github.com/fge/sample-json-schemas/tree/master/geojson
>

Oh...

Well, I did announce this project, but indeed not the fact that I had
moved the GeoJSON schemas here. Apologies!

--
Francis Galiegue, fgal...@gmail.com
JSON Schema in Java: http://json-schema-validator.herokuapp.com

Roger Costello

unread,
Jan 28, 2015, 12:56:23 PM1/28/15
to json-...@googlegroups.com
Thanks a lot Francis for creating JSON Schemas for geoJSON. I have been examining the JSON Schemas you created and I think the $ref values may be incorrect. For example, geojson.json contains this:

    "properties": {
        "crs": { "$ref": "http://json-schema.org/geojson/crs.json#" },
        "bbox": { "$ref": "http://json-schema.org/geojson/bbox.json#" }
    },

There is no crs.json file at http://json-schema.org/geojson.

However, there is a crs.json file here:

https://raw.githubusercontent.com/fge/sample-json-schemas/master/geojson/crs.json

Should the value of $ref be that URL? Ditto for the other references.

/Roger

Sebastian Lasse

unread,
Jan 29, 2015, 3:23:13 AM1/29/15
to json-...@googlegroups.com
Thankyou, guys.

Request: 
How about contributing this stuff to https://github.com/schemastore/schemastore/ ?
Would fit well ;)
Reply all
Reply to author
Forward
0 new messages