@mapbox/geojsonhint3.0.0 • Public • Published
geojsonhint: complete, fast, standards-based validation for geojson
jsonlint-lines, GeoJSON that is also not valid JSON
can return informative, line-oriented parsing errors.
The basis of this tool is the published GeoJSON specification.
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:
The options argument is optional. It has these options:
By default, geojsonhint will treat repeated properties as an error: you can set noDuplicateMembers to false to allow them. For instance:
type property in this input will be ignored with the option,
and flagged without it.
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.
With this option enabled, geojsonhint will produce these warnings:
line: 1level: 'message'message: 'precision of coordinates should be reduced'line: 1level: 'message'message: 'precision of coordinates should be reduced'
Without this option, this input will pass without errors.
Note that the GeoJSON can be given as a string or as an object. Here's how to choose which input to use:
stringinputs receive line numbers for each error. These make errors easier to track down if the GeoJSON is hand-written.
objectinputs 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
npm (node.js, browserify, webpack, etc)
npm install --save @mapbox/geojsonhint
CDN / script tag
Hit this URL to resolve to the latest pinned version.
As a command-line utility
npm install -g @mapbox/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
- Building the browser version:
npm run build