Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@davidfig/json-depth

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@davidfig/json-depth

Prettify JSON for output with a number of options, including inlining after a set depth

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

json-depth

Prettify JSON for output with a number of options, including inlining after a set depth

rationale

My OCD forced me to create this. I wanted to edit JSON files prettified to a certain depth and I couldn't find an appropriate npm package. I added other options as well.

installation

npm i @davidfig/json-depth

simple usage

const fs = require('fs')
const jsonDepth = require('json-depth')

const data = { vehicles: ['cars', 'trucks', 'motorcycles', 'bicycles'], colors: ['red', 'green', 'blue']}

console.log(jsonDepth(data, { depth: 1 }))
/* RESULT:
{
	"vehicles": ["cars", "trucks", "motorcycles", "bicycles"],
	"colors": ["red", "green", "blue"]
}
*/

fs.writeFile('test/test-output.json', jsonDepth(DATA, { depth: 2 }), () =>
{
    console.log('wrote file: test-output.json')
    process.exit(0)
})

API

// prettify JSON with more options
function jsondepth(data, options)
nametypedefaultdescription
dataobjectdata to be prettified
optionsobject
options.depthnumber3the number of depths to expand with options.eol characters
options.indentstring/ta string or the number of spaces to indent each depth
options.spacesnumber0number of spaces to use instead of indent character
options.eolstring\nend of line character
options.spaceAfternumber1spaces after bracket, squiggly bracket, comma, or colon
options.ignoreNullbooleanfalseignore null
options.ignoreUndefinedbooleantrueignore undefined entries
options.emptyArraystring[]replace empty array with this string
options.emptyObjectstring{}replace empty object with this string
options.spaceInlineArraybooleanfalsewhether to add a space at the beginning and end of an inline array
options.spaceInlineObjectbooleantruewhether to add a space at the beginning and end of an inline object

license

MIT License
(c) 2018 YOPEY YOPEY LLC by David Figatner

Keywords

FAQs

Package last updated on 08 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc