Socket
Socket
Sign inDemoInstall

json-format

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-format

JSON format for good presentation


Version published
Weekly downloads
194K
increased by3.43%
Maintainers
1
Weekly downloads
 
Created

What is json-format?

The json-format npm package is a utility for formatting JSON strings in a readable and pretty-printed manner. It allows developers to easily convert JSON objects into a human-readable format with customizable indentation and other formatting options.

What are json-format's main functionalities?

Basic Formatting

This feature allows you to format a JSON object into a readable string with default settings.

const jsonFormat = require('json-format');
const jsonObject = { name: 'John', age: 30, city: 'New York' };
const formattedJson = jsonFormat(jsonObject);
console.log(formattedJson);

Custom Indentation

This feature allows you to customize the indentation of the formatted JSON string. In this example, the indentation is set to 4 spaces.

const jsonFormat = require('json-format');
const jsonObject = { name: 'John', age: 30, city: 'New York' };
const config = { type: 'space', size: 4 };
const formattedJson = jsonFormat(jsonObject, config);
console.log(formattedJson);

Customizing Key Order

This feature allows you to specify the order of keys in the formatted JSON string. In this example, the keys are ordered as 'city', 'name', and 'age'.

const jsonFormat = require('json-format');
const jsonObject = { name: 'John', age: 30, city: 'New York' };
const config = { type: 'space', size: 2, reorderKeys: ['city', 'name', 'age'] };
const formattedJson = jsonFormat(jsonObject, config);
console.log(formattedJson);

Other packages similar to json-format

Keywords

FAQs

Package last updated on 25 Dec 2016

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