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

react-json-formatter

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-json-formatter

Formatting json data to JSX of React

  • 0.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.6K
decreased by-10.55%
Maintainers
1
Weekly downloads
 
Created
Source

react-json-formatter

React component to formate JSON data

NPM JavaScript Style Guide

Install

npm

npm i react-json-formatter

yarn

yarn add react-json-formatter

pnpm

pnpm i react-json-formatter

Usage

App.js

import React from 'react'

import JsonFormatter from 'react-json-formatter'

const App = () => {
  const sample = `{
   "string":"ABCDE",
   "number":1,
   "null":null,
   "boolean":true,
   "object":{
      "string":"ABCDE",
      "number":1,
      "null":null,
      "boolean":true
   },
   "array":[
      1,
      2,
      3,
      4,
      {
      "string":"ABCDE",
      "number":1,
      "null":null,
      "boolean":true,
         "array":[
      1,
      2,
      3,
      4,
      {
      "string":"ABCDE",
      "number":1,
      "null":null,
      "boolean":true
   }
   ]
   }
   ]
}
`

  const jsonStyle = {
    propertyStyle: { color: 'red' },
    stringStyle: { color: 'green' },
    numberStyle: { color: 'darkorange' }
  }

  return <JsonFormatter json={sample} tabWith={4} jsonStyle={jsonStyle} />
}

export default App

Demo

Demo

Attributes

json: string(Json) or valid json object

The string of Json to formate.

tabWith: number

The number of spaces it should use per tab. The default is 2.

styles

Use the Object jsonStyle to control the style of formatted JSON.

stylepart
propertyStyleThe properties of Object.
colonStyleThe colons of Object.
styleThe whole parts of the formatted JSON.
tabSpaceStyleThe space of the tabs at Object or Array.
numberStyleThe numbers in JSON.
stringStyleThe strings in JSON.
booleanStyleBoth boolean values in JSON.
trueStyleThe boolean values of true in JSON.
falseStyleThe boolean values of false in JSON.
nullStyleThe null values in JSON
commaStyleThe commas used in Array and Object
braceStyleThe braces of Object.
bracketStyleThe brackets of Array.

ClassNames

Use the Object jsonClassName to add the className to formatted JSON.

stylepart
propertyClassNameThe properties of Object.
colonClassNameThe colons of Object.
classNameThe whole parts of the formatted JSON.
tabSpaceClassNameThe space of the tabs at Object or Array.
numberClassNameThe numbers in JSON.
stringClassNameThe strings in JSON.
booleanClassNameBoth boolean values in JSON.
trueClassNameThe boolean values of true in JSON.
falseClassNameThe boolean values of false in JSON.
nullClassNameThe null values in JSON
commaClassNameThe commas used in Array and Object
braceClassNameThe braces of Object.
bracketClassNameThe brackets of Array.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT © ronny1020

Keywords

FAQs

Package last updated on 04 Jul 2023

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