geojsonhint

validate and sanity-check geojson files

This module is now under the @mapbox namespace: install @mapbox/geojsonhint instead
Last updated 8 years ago by tmcw .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ npm install geojsonhint 
SYNC missed versions from official npm registry.

Build Status Coverage Status

geojsonhint: complete, fast, standards-based validation for geojson

A lint tool for the GeoJSON standard. geojsonhint is written to the standard, with no missing or additional opinions about structure.

Thanks to jsonlint-lines, GeoJSON that is also not valid JSON can return informative, line-oriented parsing errors.

Specification

The basis of this tool is the published GeoJSON 1.0 specification. In the few cases where draft-geojson, the ietf-candidate version of GeoJSON, is more precise (for instance, the id property), the validator follows the draft spec as well.

API

errors = geojsonhint.hint(string or object, options)

Lint a file, given as a string or object. This call detects all aberrations from the GeoJSON standards and returns them as an array of errors. An example of the output:

[{
  "message": "\"features\" property should be an array, but is an object instead",
  "line": 1
}]

The options argument is optional. It has these options:

noDuplicateMembers.

By default, geojsonhint will treat repeated properties as an error: you can set noDuplicateMembers to false to allow them. For instance:

geojsonhint.hint('{"type":"invalid","type":"Feature","properties":{},"geometry":null}', {
    noDuplicateMembers: false
});

The repeated type property in this input will be ignored with the option, and flagged without it.

precisionWarning.

GeoJSON now recommends six decimal places of accuracy for coordinates (Section 11.2). This option adds a warning message when coordinates contain over 6 decimal places of accuracy, up to 10 coordinates before the warning message is truncated for performance.

geojsonhint.hint('{ "type": "Point", "coordinates": [100.0000000001, 5.0000000001] }', {
    precisionWarning: false
});

With this option enabled, geojsonhint will produce these warnings:

[{
  line: 1,
  level: 'message',
  message: 'precision of coordinates should be reduced'
}, {
  line: 1,
  level: 'message',
  message: 'precision of coordinates should be reduced'
}]

Without this option, this input will pass without errors.

Line Numbers

Note that the GeoJSON can be given as a string or as an object. Here's how to choose which input to use:

  • string inputs receive line numbers for each error. These make errors easier to track down if the GeoJSON is hand-written.
  • object inputs don't have line numbers but are evaluated faster, by up to 10x. GeoJSONHint is very fast already so unless you have identified it as a bottleneck in your application, don't prematurely optimize based on this fact.

If you're really trying to save space and don't care about JSON validity errors - only GeoJSON errors - you can require('geojsonhint/lib/object') to get a version of this library that bypasses jsonlint-lines and provides only the object interface.

use it

npm (node.js, browserify, webpack, etc)

npm install --save geojsonhint

CDN / script tag

Hit this URL to resolve to the latest pinned version.

https://unpkg.com/geojsonhint@latest/geojsonhint.js

As a command-line utility

Install:

npm install -g geojsonhint
➟ geojsonhint
Usage: geojsonhint FILE.geojson

Options:
  --json  output json-formatted data for hints
➟ geojsonhint test.geojson
line 9, each element in a position must be a number

Development

  • Tests: npm test
  • Building the browser version: npm run build

See Also

Current Tags

  • 2.0.0                                ...           latest (8 years ago)

24 Versions

  • 2.0.0 [deprecated]           ...           8 years ago
  • 2.0.0-beta2                                ...           8 years ago
  • 2.0.0-beta1                                ...           8 years ago
  • 2.0.0-beta                                ...           8 years ago
  • 1.2.1 [deprecated]           ...           9 years ago
  • 1.2.0 [deprecated]           ...           9 years ago
  • 1.1.1 [deprecated]           ...           9 years ago
  • 1.1.0 [deprecated]           ...           9 years ago
  • 1.0.1 [deprecated]           ...           9 years ago
  • 1.0.0 [deprecated]           ...           10 years ago
  • 0.3.4 [deprecated]           ...           10 years ago
  • 0.3.3 [deprecated]           ...           11 years ago
  • 0.3.2 [deprecated]           ...           11 years ago
  • 0.3.1 [deprecated]           ...           11 years ago
  • 0.3.0 [deprecated]           ...           11 years ago
  • 0.2.2 [deprecated]           ...           11 years ago
  • 0.2.1 [deprecated]           ...           11 years ago
  • 0.2.0 [deprecated]           ...           11 years ago
  • 0.1.5 [deprecated]           ...           11 years ago
  • 0.1.4 [deprecated]           ...           11 years ago
  • 0.1.2 [deprecated]           ...           11 years ago
  • 0.1.1 [deprecated]           ...           11 years ago
  • 0.1.0 [deprecated]           ...           11 years ago
  • 0.0.0 [deprecated]           ...           11 years ago
Downloads
Total 18
Today 0
This Week 0
This Month 16
Last Day 0
Last Week 16
Last Month 0
Dependencies (5)
Dev Dependencies (6)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE