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 |
|
5 | A [lint](http://bit.ly/12jjJyW) tool for the [GeoJSON](http://www.geojson.org/)
|
6 | standard. geojsonhint is written _to the standard_, with no missing or additional
|
7 | opinions about structure.
|
8 |
|
9 | Thanks to `jsonlint-lines`, GeoJSON that is also not valid [JSON](http://json.org/)
|
10 | can return informative, line-oriented parsing errors.
|
11 |
|
12 | ## Specification
|
13 |
|
14 | The basis of this tool is the published [GeoJSON](http://www.geojson.org/) 1.0 specification.
|
15 | In the few cases where [draft-geojson](https://github.com/geojson/draft-geojson/blob/master/middle.mkd),
|
16 | the 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 |
|
22 | Lint a file, given as a string or object. This call detects all aberrations from
|
23 | the 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 |
|
32 | The options argument is optional and has one option: `noDuplicateMembers`.
|
33 | By default, geojsonhint will treat repeated properties as an error: you can
|
34 | set noDuplicateMembers to false to allow them. For instance:
|
35 |
|
36 | ```js
|
37 | geojsonhint.hint('{"type":"invalid","type":"Feature","properties":{},"geometry":null}', {
|
38 | noDuplicateMembers: false
|
39 | });
|
40 | ```
|
41 |
|
42 | The repeated `type` property in this input will be ignored with the option,
|
43 | and flagged without it.
|
44 |
|
45 | ## Line Numbers
|
46 |
|
47 | Note that the GeoJSON can be given as a **string or as an object**. Here's how
|
48 | to 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 |
|
57 | For byte-minimalists, you can `require('geojsonhint/object')` to get a version
|
58 | of this library that bypasses jsonlint-lines and provides only the object
|
59 | interface.
|
60 |
|
61 | ## use it
|
62 |
|
63 | as a library
|
64 |
|
65 | npm install --save geojsonhint
|
66 |
|
67 | as 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 |
|
73 | Install:
|
74 |
|
75 | npm install -g geojsonhint
|
76 |
|
77 | ```
|
78 | ➟ geojsonhint
|
79 | Usage: geojsonhint FILE.geojson
|
80 |
|
81 | Options:
|
82 | --json output json-formatted data for hints
|
83 | ```
|
84 |
|
85 | ```
|
86 | ➟ geojsonhint test.geojson
|
87 | line 9, each element in a position must be a number
|
88 | ```
|
89 |
|
90 | ## developing
|
91 |
|
92 | Tests:
|
93 |
|
94 | npm test
|
95 |
|
96 | Building 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
|