# @mapbox/geojsonhint

> validate and sanity-check geojson files

Latest version **3.3.0** (published 2023-11-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install @mapbox/geojsonhint
pnpm add @mapbox/geojsonhint
yarn add @mapbox/geojsonhint
bun add @mapbox/geojsonhint
```

Provides the command `geojsonhint`.

## Health

**Score 5/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.3.0 |
| Published | 2023-11-10 |
| First published | 2016-12-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 83.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 255 |
| Author | Tom MacWright |
| Maintainers | mbx-npm-ci-production, mbx-npm-ci-staging, mbx-npm-advanced-actions-production, mbx-npm-advanced-actions-staging, mbx-npm-09-production, mbx-npm-08-production, mbx-npm-07-production, mbx-npm-06-production, mbx-npm-05-production, mbx-npm-04-production, mbx-npm-03-production, mbx-npm-02-production, mbx-npm-01-production, mbx-npm-02-staging, mapbox-npm-01, mapbox-npm-02, mapbox-npm-07, mapbox-npm-03, mapbox-npm-04, mapbox-npm-09, mapbox-npm-05, mapbox-npm-06, mapbox-npm-08, mapbox-npm-advanced-actions, mapbox-npm-ci, mapbox-npm, mapbox-admin, mapbox-machine-user |
| Keywords | geojson, hint |

## Links

- npm: https://www.npmjs.com/package/@mapbox/geojsonhint
- Repository: https://github.com/mapbox/geojsonhint
- Homepage: https://github.com/mapbox/geojsonhint#readme
- Issues: https://github.com/mapbox/geojsonhint/issues
- npm.io page: https://npm.io/package/@mapbox/geojsonhint

## Dependencies (6)

- [vfile](https://npm.io/package/vfile.md) ^4.0.0
- [minimist](https://npm.io/package/minimist.md) ^1.2.8
- [concat-stream](https://npm.io/package/concat-stream.md) ^1.6.1
- [jsonlint-lines](https://npm.io/package/jsonlint-lines.md) ^1.7.1
- [vfile-reporter](https://npm.io/package/vfile-reporter.md) ^5.1.1
- [@gerhobbelt/nomnom](https://npm.io/package/@gerhobbelt/nomnom.md) github:gerhobbelt/nomnom

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 3.3.0 (latest) — 2023-11-10
- 3.1.1-dev (dev) — 2023-03-24
- 3.2.0 — 2023-06-27
- 3.1.1 — 2023-03-24
- 3.1.0 — 2022-08-25
- 3.1.0-beta.1 — 2022-08-25
- 3.0.2 — 2022-08-25
- 3.1.0-beta — 2022-08-24
- 3.0.1 — 2021-05-11
- 3.0.0 — 2019-03-26
- 2.2.0 — 2019-03-26
- 2.1.0 — 2018-03-16
- 2.0.1 — 2017-02-21
- 1.2.1 — 2016-12-02
- 2.0.0 — 2016-12-02

## README

[![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)

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

Important: development of geojsonhint is currently paused. Until development restarts, please refrain from adding non-critical issues or PRs.

A [lint](https://en.wikipedia.org/wiki/Lint_%28software%29) tool for the [GeoJSON](https://tools.ietf.org/html/rfc7946)
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](http://json.org/)
can return informative, line-oriented parsing errors.

## Specification

The basis of this tool is the published [GeoJSON](https://tools.ietf.org/html/rfc7946) specification.

## 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:

```json
[{
  "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:

```js
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](https://tools.ietf.org/html/rfc7946#section-11.2)
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.

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

With this option enabled, geojsonhint will produce these warnings:

```js
[{
  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.

`ignoreRightHandRule`.

GeoJSON specification defined that linear rings must follow right-hand rule, but also says that for backward compatibility reasons parsers should not rejects polygons wiht incorrect winding order. For that kind of situations geojsonhint has an option `ignoreRightHandRule` which is `false` by default. Setting this option to `true` will cause geojsonhint to skip right-hand rule validation.

```js
geojsonhint.hint(geojsonWithIncorrectWindingOrder, {
  ignoreRightHandRule: true
});
````

with this option enabled, geojsonhint will not validate winding order.

## 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](http://c2.com/cgi/wiki?PrematureOptimization) 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 @mapbox/geojsonhint

**CDN / script tag**

Hit this URL to resolve to the latest pinned version.

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

## As a command-line utility

Install:

    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
```

## Development

* Tests: `npm test`
* Building the browser version: `npm run build`

## See Also

* [grunt-geojsonhint](https://github.com/jieter/grunt-geojsonhint) does it as a Grunt task
* [GeoJSON-Validation](https://github.com/craveprogramminginc/GeoJSON-Validation) is another node module for this.
* [geojson-assert](https://github.com/calvinmetcalf/geojson-assert) does it in assertion tests
* [geojsonlint](https://github.com/ropenscilabs/geojsonlint) does it in an R package

---
_Source: https://npm.io/package/@mapbox/geojsonhint · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
