0.4.0 • Published 10 months ago

react-json-formatter v0.4.0

Weekly downloads
13
License
MIT
Repository
github
Last release
10 months ago

react-json-formatter

React component to formate JSON data

NPM JavaScript Style Guide

Install

npm 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)

The string of Json to formate.

tabWith: number

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

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

0.4.0

10 months ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

4 years ago

0.1.0

4 years ago