# detect-json-style

> Detect style of formatted tabular data from a first chunk

Latest version **1.0.2** (published 2014-11-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install detect-json-style
pnpm add detect-json-style
yarn add detect-json-style
bun add detect-json-style
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2014-11-20 |
| First published | 2014-11-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Finn Pauls |
| Maintainers | finnpauls |
| Keywords | detect, peek |

## Links

- npm: https://www.npmjs.com/package/detect-json-style
- Repository: https://github.com/finnp/detect-json-style
- Issues: https://github.com/finnp/detect-json-style/issues
- npm.io page: https://npm.io/package/detect-json-style

## Recent versions

- 1.0.2 (latest) — 2014-11-20
- 1.0.1 — 2014-11-19
- 1.0.0 — 2014-11-19

## README

# detect-json-style
Windows | Mac/Linux
------- | ---------
[![Windows Build status](http://img.shields.io/appveyor/ci/finnp/detect-json-style.svg)](https://ci.appveyor.com/project/finnp/detect-json-style/branch/master) | [![Build Status](https://travis-ci.org/finnp/detect-json-style.svg?branch=master)](https://travis-ci.org/finnp/detect-json-style)


Detect JSON type from a first peek chunk of a string. 

It detects the following styles
* *object* Array top-level nested in an object like `{"rows": [{"a": 1}, ..]`
* *array*  Array of objects `[{"a": 1}...]`
* *multiline* JSON objects after each other `{"a: 1"}{"a": 2}` (can be ndjson)


## usage

```js
var detectJSON = require('detect-json-style')
var json = detectJSON('{"rows": [{"a": 1}, {"a": 2}, {"a":')
// json -> {style: 'object', selector: 'rows.*'}
```


Works well together with `peek-stream` and `JSONStream`. The selector 
attribute is compatible with the first argument of `JSONStream.parse()`.

```js
var peek = require('peek-stream')
var JSONStream = require('JSONStream')
var detectJSON = require('detect-json-style')

peek(function (data, swap) {
  var json = detectJSON(swap)
  if(json) swap(null, JSONStream.parse(json.selector))
    
  swap(new Error('Could not determine format'))
})


```

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