# dankjson

> Dankest JSON read/write module around

Latest version **1.0.7** (published 2017-06-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install dankjson
pnpm add dankjson
yarn add dankjson
bun add dankjson
```

## 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.7 |
| Published | 2017-06-07 |
| First published | 2017-04-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Aeirety |
| Maintainers | aeirety |
| Keywords | json |

## Links

- npm: https://www.npmjs.com/package/dankjson
- npm.io page: https://npm.io/package/dankjson

## Dependencies (1)

- [promise](https://npm.io/package/promise.md) ^7.1.1

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

- 1.0.7 (latest) — 2017-06-07
- 1.0.6 — 2017-05-25
- 1.0.5 — 2017-05-25
- 1.0.4 — 2017-05-25
- 1.0.2 — 2017-04-13
- 1.0.1 — 2017-04-13
- 1.0.0 — 2017-04-09

## README

![Cover photo](http://i.imgur.com/a3TY25l.png)

# Dank JSON

* Simplifies JSON reading & writing
* Configuration reading into singleton object with configuration defaults

## Reading

| Parameter | Optional | Type   | Description                 |
|-----------|----------|--------|-----------------------------|
| file      | false    | String | Path to the file to be read |

This example reads and logs the contents of fruits.json

```js
const dj = require("dankjson");

dj("fruits.json").then(object => console.log(object));
```

## Writing

| Parameter | Optional | Type   | Description                      |
|-----------|----------|--------|----------------------------------|
| file      | false    | String | Path to the file to be read      |
| object    | false    | Object | JSON object to be writen to file |
| tabSize   | true     | Number | Indentation tab size             |

This example writes the colors object to colors.json with 4 space indentation

```js
const dj = require("dankjson");

let colors = {
    red: {
        r: 255,
        g: 0,
        b: 0
    },
    blue: {
        r: 0,
        g: 0,
        b: 255
    }
}

dj("colors.json", colors, 4);
```

## Reading to config

| Parameter | Optional | Type          | Description                                            |
|-----------|----------|---------------|--------------------------------------------------------|
| files     | false    | Array<String> | Paths to the files to be read into config              |
| defaults  | true     | Array<Object> | JSON objects to be writen to file if it does not exist |
| tabSize   | true     | Number        | Indentation tab size                                   |

This example reads config.json into config and logs it. If the config does not exists it writes the default with 4 space indentation

```js
const dj = require("dankjson");

let configDefault {
    ip: "",
    port: 80,
    messages: [
        "Hello, world.",
        "Bye, world."
    ]
}

dj(["config.json"], [configDefault], 4).then(config => console.log(config));
```

## Getting config

This example gets and logs the config

```js
const dj = require("dankjson");

dj().then(config => console.log(config));
```

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