You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

json-to-plain-text

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-to-plain-text - npm Package Compare versions

Comparing version

to
1.1.0

dist/cjs/index.d.ts

42

package.json
{
"name": "json-to-plain-text",
"version": "1.0.5",
"description": "Convert any json to plain text",
"main": "index.js",
"directories": {
"lib": "lib",
"test": "test"
"version": "1.1.0",
"description": "json-to-plain-text",
"main": "dist/cjs/index.js",
"module": "dist/index.js",
"type": "module",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/cjs/index.js"
},
"./package.json": "./package.json"
},
"types": "./typings/index.d.ts",
"scripts": {
"test": "node index.js"
"build": "rm -rf dist && tsc",
"build:cjs": "tsc && npm run echo:type-cjs",
"echo:type-cjs": "echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
"test": "jest",
"eslint": "npx eslint .",
"prettier": "npx prettier --write ."
},

@@ -18,6 +29,9 @@ "repository": {

"keywords": [
"jsonToPlainText",
"json",
"plain",
"text",
"convertor"
"convert",
"convertor",
"normal"
],

@@ -31,4 +45,14 @@ "author": "sumithemmadi",

"devDependencies": {
"prettier": "2.7.1"
"@types/node": "^20.4.2",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"eslint": "^8.45.0",
"jest": "^29.6.1",
"prettier": "^3.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
},
"dependencies": {
"chalk": "^4.1.2"
}
}

@@ -1,24 +0,45 @@

<h1 id="json-to-plain-text"><a href="https://github.com/sumithemmadi/json-to-plain-text">json-to-plain-text</a></h1>
# jsonToPlainText
<a href="https://www.npmjs.com/package/json-to-plain-text"><img src="https://img.shields.io/npm/v/json-to-plain-text.svg" alt="Version"></a>
<a href="https://github.com/sumithemmadi/json-to-plain-text/stargazers"><img src="https://img.shields.io/github/stars/sumithemmadi/json-to-plain-text" alt="Stars"></a>
<a href="https://github.com/sumithemmadi/json-to-plain-text"><img src="https://img.shields.io/npm/dt/json-to-plain-text.svg" alt="weekly Download"></a>
<a href="https://github.com/sumithemmadi/json-to-plain-text/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/json-to-plain-text.svg" alt="License"></a>
<a href="https://github.com/sumithemmadi/json-to-plain-text"><img src="https://img.shields.io/npms-io/maintenance-score/json-to-plain-text" alt="Maintenance"></a>
<a href="https://github.com/sumithemmadi/json-to-plain-text/issues"><img src="https://img.shields.io/github/issues/sumithemmadi/json-to-plain-text" alt="issues"></a>
<br>
<p>Convert any json to plain text.</p>
`json-to-plain-text` is a npm module that converts JSON-like data or plain JavaScript objects to a formatted plain text representation. It allows you to convert complex data structures into a more human-readable and structured format for better understanding and debugging.
## Installation
## Installation
```
npm install json-to-plain-text
```
1. Install `json-to-plain-text` npm package.
```bash
npm install json-to-plain-text
```
2. Import the `jsonToPlainText` function:
```typescript
import { jsonToPlainText } from "json-to-plain-text";
```
## Usage
```js
var convert = require('json-to-plain-text');
The `jsonToPlainText` function accepts two parameters: `data` and `options`.
var jsonData = {
### Parameters
- `data` (required): The input data to convert. It can be JSON-like data or plain JavaScript objects.
- `options` (optional): Configuration options for customizing the output. It is an object with the following properties:
- `color` (boolean, default: `true`): Whether to apply colors to the output or not. Set to `true` to add colors using the `chalk` library or `false` for plain text output.
- `spacing` (boolean, default: `true`): Whether to include spacing after colons. Set to `true` for formatted spacing or `false` to remove spacing after colons.
- `squareBracketsForArray` (boolean, default: `false`): Whether to use square brackets for arrays. Set to `true` to enclose arrays in square brackets or `false` to display arrays without brackets.
- `doubleQuotesForKeys` (boolean, default: `false`): Whether to use double quotes for object keys. Set to `true` to wrap object keys in double quotes or `false` to keep them as they are.
- `doubleQuotesForValues` (boolean, default: `false`): Whether to use double quotes for string values. Set to `true` to add double quotes around string values or `false` to display them without quotes.
### Example
```typescript
import { jsonToPlainText } from "json-to-plain-text";
const data = {
"place_id": "173937105",

@@ -51,81 +72,47 @@ "osm_type": "way",

var response = convert.toPlainText(jsonData);
console.log(response);
// This is optional
const options = {
color: true; // Whether to apply colors to the output or not
spacing: true; // Whether to include spacing after colons or not
squareBracketsForArray: false; // Whether to use square brackets for arrays or not
doubleQuotesForKeys: false; // Whether to use double quotes for object keys or not
doubleQuotesForValues: false; // Whether to use double quotes for string values or not
}
// Convert the data to formatted plain text representation
const plainText = jsonToPlainText(data, options);
console.log(plainText);
```
## Output
### Output
```yaml
place_id : 173937105
osm_type : way
osm_id : 319992693
lat : 17.861533866867224
lon : 78.8081441896764
display_name : Satadar Nagar, Ward 116 Allapur, Hyderabad, Kukatpally mandal, Telangana, 500018, India
address :
neighbourhood : Satadar Nagar
suburb : Ward 116 Allapur
city : Hyderabad
county : Kukatpally mandal
state : Telangana
postcode : 500018
country : India
country_code : in
extratags : {}
namedetails : {}
boundingbox : 17.8598497, 17.8623087, 78.8079136, 78.8082658
distance : 2
place_id : 173937105
osm_type : way
osm_id : 319992693
lat : 17.861533866867224
lon : 78.8081441896764
display_name : Satadar Nagar, Ward 116 Allapur, Hyderabad, Kukatpally mandal, Telangana, 500018, India
address :
neighbourhood : Satadar Nagar
suburb : Ward 116 Allapur
city : Hyderabad
county : Kukatpally mandal
state : Telangana
postcode : 500018
country : India
country_code : in
extratags : {}
namedetails : {}
boundingbox : 17.8598497, 17.8623087, 78.8079136, 78.8082658
distance : 2
```
## Coloured output
```js
// var response = convert.toPlainText(jsonData, color,spacing);
var response = convert.toPlainText(jsonData,true,true);
console.log(response);
```
- no space required after property name's
```js
// var response = convert.toPlainText(jsonData, color,spacing);
var response = convert.toPlainText(jsonData,true,false);
console.log(response);
// place_id : 173937105
// osm_type : way
// osm_id : 319992693
// lat : 17.861533866867224
// lon : 78.8081441896764
// display_name : Satadar Nagar, Ward 116 Allapur, Hyderabad, Kukatpally mandal, Telangana, 500018, India
// address :
// neighbourhood : Satadar Nagar
// suburb : Ward 116 Allapur
// city : Hyderabad
// county : Kukatpally mandal
// state : Telangana
// postcode : 500018
// country : India
// country_code : in
// extratags : {}
// namedetails : {}
// boundingbox : 17.8598497, 17.8623087, 78.8079136, 78.8082658
// distance : 2
```
## License
MIT License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
Copyright (c) 2021 **Emmadi Sumith Kumar**
## Author
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
- [Sumith Emmadi](https://github.com/sumithemmadi)