# pojo-dump

> JSON printer, print JSON or any POJO to terminal or debug window

Latest version **1.4.0** (published 2025-10-15) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install pojo-dump
pnpm add pojo-dump
yarn add pojo-dump
bun add pojo-dump
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.4.0 |
| Published | 2025-10-15 |
| First published | 2025-07-23 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10.0 |
| Dependencies | 2 |
| Unpacked size | 29 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | streamich |
| Maintainers | streamich |
| Keywords | json, tree, pojo, print, dump, json dump, print json |

## Links

- npm: https://www.npmjs.com/package/pojo-dump
- Repository: https://github.com/streamich/pojo-dump
- Issues: https://github.com/streamich/pojo-dump/issues
- Funding: https://github.com/sponsors/streamich
- npm.io page: https://npm.io/package/pojo-dump

## Dependencies (2)

- [tree-dump](https://npm.io/package/tree-dump.md) ^1.0.3
- [@jsonjoy.com/json-random](https://npm.io/package/@jsonjoy.com/json-random.md) ^1.2.0

## 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.4.0 (latest) — 2025-10-15
- 1.3.0 — 2025-08-23
- 1.2.0 — 2025-08-19
- 1.1.0 — 2025-07-23

## README

# `pojo-dump`

Prints a JSON structure (or any POJO) to the console. Can print to a single line
or to a tree structure.


## Installation

Install the package using NPM or Yarn:

```bash
npm install pojo-dump
# or
yarn add pojo-dump
```


## Exports

The library provides the following exports:

- `toLine`: Formats data into a compact, single-line JSON-like representation.
- `toTree`: Formats data into a tree-like structure for better readability.
- `logTree`: Logs the tree-like structure to the console.


## Usage

Print to a single line:

```js
import { toLine } from 'pojo-dump';

const data = [null, true, false, 123, 0.1, 'as\ndf', [1, 2, 3], { foo: 'bar' }];
console.log(toLine(data));
// [ !n, !t, !f, 123, .1, "as" ⏎ "df", [ 1, 2, 3 ], { foo = "bar" } ]
```

Print to a multi-line tree layout:

```js
import { toTree } from 'pojo-dump';

const data = { foo: 'bar', nested: [1, 2, { key: 'value' }] };
console.log(toTree(data));

/*
Output:
╿
├─ foo = "bar"
└─ nested
   ├─ [0]: 1
   ├─ [1]: 2
   └─ [2]
      └─ key = "value"
*/
```


## Formatting choices

- Constant literals:
  ```ts
  console.log(toLine([true, false, null, undefined]));
  // Output: [ !t, !f, !n, !u ]
  ```

- Number literals:
  ```ts
  console.log(toLine([1000, 0.1]));
  // Output: [ 1,000, .1 ]
  ```

- Formatting strings with special characters:
  ```ts
  console.log(toLine('hello\nworld'));
  // Output: "hello" ⏎ "world"
  ```

- Formatting binary data:
  ```ts
  console.log(toLine(new Uint8Array([104, 101, 108, 108, 111])));
  // Output: Uint8Array { 68 65 6C 6C 6F }
  ```


## License

Apache 2.0

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