# json-influx

> Converts JSON input to InfluxDB line protocol format

Latest version **0.3.0** (published 2017-01-05) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install json-influx
pnpm add json-influx
yarn add json-influx
bun add json-influx
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2017-01-05 |
| First published | 2017-01-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Evan Shortiss |
| Maintainers | kmeillet |
| Keywords | influxdb, influx, json, line, protocol |

## Links

- npm: https://www.npmjs.com/package/json-influx
- Repository: https://github.com/evanshortiss/node-json-to-influx-line
- Homepage: https://github.com/evanshortiss/node-json-to-influx-line#readme
- Issues: https://github.com/evanshortiss/node-json-to-influx-line/issues
- npm.io page: https://npm.io/package/json-influx

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

- 0.3.0 (latest) — 2017-01-05
- 0.2.0 — 2017-01-02

## README

# JSON to InfluxDB Line Protocol
Module that will convert a JSON Object to the line protocol format for
InfluxDB. Will perform any necessary escaping on strings as specified by the
protocol. You can read about the InfluxDB line protocol [here](https://docs.influxdata.com/influxdb/v0.12/write_protocols/write_syntax/#line-protocol).

This module does not perform any I/O to InfluxDB. It is just a converter.

This is the initial version and has not been thoroughly tested in real world
scenarios, nor performance tested. A suite of unit tests are passing however.

# Install
```
npm i json-influxdb-line
```

# Usage

Any Object you want to convert to a line must be of the format:

```js
{
  measurement: 'name-of-measure',
  // Fields cannot contain sub-objects unless they are stringified
  fields: {
    c: '2',
    d: 3
  },
  // Options. Tags cannot contain sub-objects unless they are stringified
  tags: {
    a: '1',
    b: 2
  },
  // Optional. Any precision can be used (see InfluxDB API)
  ts: Date.now()
}
```

## Streaming
```js
var JsonInfluxDbStream = require('json-influxdb-line').JsonInfluxDbStream;

var jsonToLine = new JsonInfluxDBLineStream();

// Get JSON (stringified objects), convert to line format, write to influxdb
getJsonStream()
  .pipe(jsonToLine)
  .pipe(influxApiStream);
```

## Functional
```js
var convert = require('json-influxdb-line').convert;

// This will create a String with the contents:
// measurement-name,foo=bar value=15 1461108623664
var line = convert({
  // A measurement name
  measurement: 'measurement-name',

  // Optional tags. Nested objects are not supported
  tags: {
    foo: 'bar'
  },

  // Fields. Nested objects are not supported
  fields: {
    value: 15
  },

  // Timestamp - can be omitted
  ts: Date.now()
});
```

# Contributions
All are welcome, just open a Pull Request and add tests where necessary.

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