4

I am new to JSON and GeoJSON and would like to start to use this but I am a little confused about some things. Perhaps you can help me out:

1) Is there a GeoJSON validator out there? 2) Is the text below valid GeoJSON? To be a valid GeoJSON file do all the GeoJSON objects have to live in a GeoJSON array or can they be stored willie nellie as below?

The data below is a return from the geocouch example on github:

{
"rows": [
    {
        "id": "augsburg",
        "bbox": [
            10.898333,
            48.371667,
            10.898333,
            48.371667
        ],
        "geometry": {
            "type": "Point",
            "coordinates": [
                10.898333,
                48.371667
            ]
        },
        "value": [
            "augsburg",
            [
                10.898333,
                48.371667
            ]
        ]
    },
    {
        "id": "oakland",
        "bbox": [
            -122.270833,
            37.804444,
            -122.270833,
            37.804444
        ],
        "geometry": {
            "type": "Point",
            "coordinates": [
                -122.270833,
                37.804444
            ]
        },
        "value": [
            "oakland",
            [
                -122.270833,
                37.804444
            ]
        ]
    }
]

}

0

2 Answers 2

4

GeoJSON is also simply JSON, so I usually run it through the validator at http://jsonlint.com/ to check it passes this first. Unfortunately I don't think there is an online validator specific to GeoJSON.

You can however use the GDAL GeoJSON driver to try and load or get information about the dataset - if it fails it's invalid. You can also use the Python Shapely library to check features as it uses a GeoJSON-like notation for geometry.

Your example seems to be missing some type attributes - features must have a type attribute and can be grouped in collections if needed. The key criteria for GeoJSON objects (from the spec) are:

  • GeoJSON always consists of a single object
  • The GeoJSON object may have any number of members (name/value pairs).
  • The GeoJSON object must have a member with the name "type"
  • The value of the type member must be one of: "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "GeometryCollection", "Feature", or "FeatureCollection". The case of the type member values must be as shown here.
  • A GeoJSON object may have an optional "crs" member, the value of which must be a coordinate reference system object
  • A GeoJSON object may have a "bbox" member, the value of which must be a bounding box array

The GDAL driver also had issues if I did not set a "crs" value

For more details take a look at the full GeoJSON specification and examples.

I also found the GeoJSON from CloudMade's services very useful for comparison - http://developers.cloudmade.com/projects/geocoding/examples

6
  • GeoJSON validation will be problematic. Does a "geometry" property have to be paired with a "type:Feature" property? To be a GeoJSON Feature, yes. But do objects necessarily have to be contained within a GeoJSON FeatureCollection to be valid Features? I argue not. The object above (with "rows") isn't a Feature Collection but it does contain Features (or almost-Features).
    – sgillies
    Commented Jun 17, 2011 at 22:59
  • @sgillies - well having one of the creators of the spec on this question certainly helps ;-) While you're here - according to the spec a CRS is not required correct? The GDAL driver seems to crash without it (in the last version I tested) Commented Jun 17, 2011 at 23:10
  • updated to state features need not be in feature collections and details from spec Commented Jun 17, 2011 at 23:16
  • GeoJSON Lint is an online validator of sorts. It should take care most of the worst.
    – Chris vCB
    Commented Nov 10, 2014 at 22:10
  • I disagree with the first sentence because there is a big difference between .geojson and .json as .geojson contains coordinates which are stored in 1x2 or 1x3 arrays of numbers and their structure should be compatible with geometry type.
    – ArashMad
    Commented Nov 17, 2020 at 20:12
1

I don't know of a validator but there is a spec (http://geojson.org/geojson-spec.html) you can consult.

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