Skip to content

json-to-plain-text is a lightweight npm package that converts JSON into a clean, human-readable plain-text.

License

Notifications You must be signed in to change notification settings

sumithemmadi/json-to-plain-text

Repository files navigation

json-to-plain-text

Version Stars Downloads License Maintenance Issues GitHub Sponsors Install size Bundle size Known Vulnerabilities


πŸ“– Overview

json-to-plain-text is a lightweight npm package that converts JSON into a clean, human-readable plain-text.

Think of it as JSON.stringify(), but prettier, friendlier, and tailored for logs, debugging, and CLI output.

Note

From version 2.0.0+, this package outputs plain text only.
If you need colored output, please use version 1.1.4 .


✨ Features

  • πŸ”Ή Convert JSON objects into easy-to-read plain text
  • ⚑ Tiny & fast (zero dependencies)
  • πŸ›  Configurable separators, spacing, quotes, and array formatting
  • βœ… Great for logs, debugging, reports, and CLI tools

πŸ” Why use this?

Use json-to-plain-text when you need:

  • πŸ“‘ Readable logs – no more squinting at raw JSON
  • πŸ–₯ CLI outputs – format objects neatly for the terminal
  • πŸ§ͺ Debugging helpers – quickly inspect nested objects
  • πŸ“ Reports/configs – human-friendly data printing

πŸš€ Installation

npm install json-to-plain-text

πŸ“¦ Usage

import { jsonToPlainText } from "json-to-plain-text";

βš™οΈ API

jsonToPlainText(data: unknown, options?: Options): string

Parameters

  • data (required) – JSON-like input or JavaScript object.
  • options (optional) – Customize the formatting.
Option Type Default Description
separator string : Character used between keys and values.
spacing boolean true Align keys with spacing before colons.
squareBracketsForArray boolean false Display arrays inside [].
doubleQuotesForKeys boolean false Wrap object keys in double quotes.
doubleQuotesForValues boolean false Wrap string values in double quotes.

πŸ’‘ Example

import { jsonToPlainText, Options } from "json-to-plain-text";

const data = {
  place_id: "173937105",
  osm_type: "way",
  lat: "17.861533866867224",
  lon: "78.8081441896764",
  address: {
    city: "Hyderabad",
    state: "Telangana",
    country: "India",
  },
  distance: 2,
};

const options: Options = {
  separator: ":",
  spacing: true,
  squareBracketsForArray: false,
  doubleQuotesForKeys: false,
  doubleQuotesForValues: false,
};

console.log(jsonToPlainText(data, options));

βœ… Output

place_id : 173937105
osm_type : way
lat      : 17.861533866867224
lon      : 78.8081441896764
address  : 
city     : Hyderabad
state    : Telangana
country  : India
distance : 2

πŸ’ Support

If this project helps you, consider supporting my open-source work:

A huge thanks to all sponsors for supporting my work!


πŸ“œ License

This project is licensed under the MIT License.


πŸ‘¨β€πŸ’» Author

Sponsor this project

  •  

Packages

No packages published

Contributors 2

  •  
  •