UNPKG

3.56 kBMarkdownView Raw
1[![Build Status](https://secure.travis-ci.org/mapbox/geojsonhint.svg?branch=master)](http://travis-ci.org/mapbox/geojsonhint) [![Coverage Status](https://coveralls.io/repos/mapbox/geojsonhint/badge.svg)](https://coveralls.io/r/mapbox/geojsonhint)
2
3# geojsonhint: complete, fast, standards-based validation for geojson
4
5A [lint](http://bit.ly/12jjJyW) tool for the [GeoJSON](http://www.geojson.org/)
6standard. geojsonhint is written _to the standard_, with no missing or additional
7opinions about structure.
8
9Thanks to `jsonlint-lines`, GeoJSON that is also not valid [JSON](http://json.org/)
10can return informative, line-oriented parsing errors.
11
12## Specification
13
14The basis of this tool is the published [GeoJSON](http://www.geojson.org/) 1.0 specification.
15In the few cases where [draft-geojson](https://github.com/geojson/draft-geojson/blob/master/middle.mkd),
16the ietf-candidate version of GeoJSON, is more precise (for instance, [the id property](https://github.com/mapbox/geojsonhint/issues/24)), the validator follows the draft spec as well.
17
18## API
19
20`errors = geojsonhint.hint(string or object, options)`
21
22Lint a file, given as a string or object. This call detects all aberrations from
23the GeoJSON standards and returns them as an array of errors. An example of the output:
24
25```json
26[{
27 "message": "\"features\" property should be an array, but is an object instead",
28 "line": 1
29}]
30```
31
32The options argument is optional and has one option: `noDuplicateMembers`.
33By default, geojsonhint will treat repeated properties as an error: you can
34set noDuplicateMembers to false to allow them. For instance:
35
36```js
37geojsonhint.hint('{"type":"invalid","type":"Feature","properties":{},"geometry":null}', {
38 noDuplicateMembers: false
39});
40```
41
42The repeated `type` property in this input will be ignored with the option,
43and flagged without it.
44
45## Line Numbers
46
47Note that the GeoJSON can be given as a **string or as an object**. Here's how
48to choose which input to use:
49
50* `string` inputs receive **line numbers for each error**. These make errors
51 easier to track down if the GeoJSON is hand-written.
52* `object` inputs don't have line numbers but are evaluated faster, by up to 10x.
53 GeoJSONHint is _very fast already_ so unless you have identified it as a
54 bottleneck in your application, don't [prematurely optimize](http://c2.com/cgi/wiki?PrematureOptimization) based
55 on this fact.
56
57For byte-minimalists, you can `require('geojsonhint/object')` to get a version
58of this library that bypasses jsonlint-lines and provides only the object
59interface.
60
61## use it
62
63as a library
64
65 npm install --save geojsonhint
66
67as a web library
68
69 curl https://raw.github.com/mapbox/geojsonhint/master/geojsonhint.js > geojsonhint.js
70
71## As a command-line utility
72
73Install:
74
75 npm install -g geojsonhint
76
77```
78➟ geojsonhint
79Usage: geojsonhint FILE.geojson
80
81Options:
82 --json output json-formatted data for hints
83```
84
85```
86➟ geojsonhint test.geojson
87line 9, each element in a position must be a number
88```
89
90## developing
91
92Tests:
93
94 npm test
95
96Building the browser version:
97
98 npm install -g browserify
99 make
100
101## See Also
102
103* [geojsonhint online](https://www.mapbox.com/geojsonhint/)
104* [grunt-geojsonhint](https://github.com/jieter/grunt-geojsonhint) does it as a Grunt task
105* [geojsonlint.com](http://geojsonlint.com/) does this server-side
106* [GeoJSON-Validation](https://github.com/craveprogramminginc/GeoJSON-Validation) is another node module for this.
107* [geojson-assert](https://github.com/calvinmetcalf/geojson-assert) does it in assertion tests