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)`
|
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 | ## Line Numbers
|
33 |
|
34 | Note that the GeoJSON can be given as a **string or as an object**. Here's how
|
35 | to choose which input to use:
|
36 |
|
37 | * `string` inputs receive **line numbers for each error**. These make errors
|
38 | easier to track down if the GeoJSON is hand-written.
|
39 | * `object` inputs don't have line numbers but are evaluated faster, by up to 10x.
|
40 | GeoJSONHint is _very fast already_ so unless you have identified it as a
|
41 | bottleneck in your application, don't [prematurely optimize](http://c2.com/cgi/wiki?PrematureOptimization) based
|
42 | on this fact.
|
43 |
|
44 | For byte-minimalists, you can `require('geojsonhint/object')` to get a version
|
45 | of this library that bypasses jsonlint-lines and provides only the object
|
46 | interface.
|
47 |
|
48 | ## use it
|
49 |
|
50 | as a library
|
51 |
|
52 | npm install --save geojsonhint
|
53 |
|
54 | as a web library
|
55 |
|
56 | curl https://raw.github.com/mapbox/geojsonhint/master/geojsonhint.js > geojsonhint.js
|
57 |
|
58 | ## As a command-line utility
|
59 |
|
60 | Install:
|
61 |
|
62 | npm install -g geojsonhint
|
63 |
|
64 | ```
|
65 | ➟ geojsonhint
|
66 | Usage: geojsonhint FILE.geojson
|
67 |
|
68 | Options:
|
69 | --json output json-formatted data for hints
|
70 | ```
|
71 |
|
72 | ```
|
73 | ➟ geojsonhint test.geojson
|
74 | line 9, each element in a position must be a number
|
75 | ```
|
76 |
|
77 | ## developing
|
78 |
|
79 | Tests:
|
80 |
|
81 | npm test
|
82 |
|
83 | Building the browser version:
|
84 |
|
85 | npm install -g browserify
|
86 | make
|
87 |
|
88 | ## See Also
|
89 |
|
90 | * [geojsonhint online](https://www.mapbox.com/geojsonhint/)
|
91 | * [grunt-geojsonhint](https://github.com/jieter/grunt-geojsonhint) does it as a Grunt task
|
92 | * [geojsonlint.com](http://geojsonlint.com/) does this server-side
|
93 | * [GeoJSON-Validation](https://github.com/craveprogramminginc/GeoJSON-Validation) is another node module for this.
|
94 | * [geojson-assert](https://github.com/calvinmetcalf/geojson-assert) does it in assertion tests
|