https://github.com/streamich/pojo-dump
Print JSON (or any POJO) to a nicely formatted human-readable text
https://github.com/streamich/pojo-dump
Last synced: 11 months ago
JSON representation
Print JSON (or any POJO) to a nicely formatted human-readable text
- Host: GitHub
- URL: https://github.com/streamich/pojo-dump
- Owner: streamich
- License: apache-2.0
- Created: 2025-07-23T07:19:56.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2025-07-23T08:14:32.000Z (11 months ago)
- Last Synced: 2025-07-23T09:29:42.326Z (11 months ago)
- Language: TypeScript
- Homepage:
- Size: 123 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
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