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

react-json-parser

Package Overview
Dependencies
Maintainers
5
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-json-parser

Transforms a JSX string to a JSON tree

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
increased by33.33%
Maintainers
5
Weekly downloads
 
Created
Source

react-json-parser

Transforms a JSX string to a JSON tree

Installation

npm install react-json-parser

CLI Usage

react-json-parser [options]

Options

-h, --help                     output usage information
-V, --version                  output the version number
-f, --file <file>              JSX file to read, defaults to stdin if not set
-o, --output <output>          JSON destination file, defaults to stdout if not set
-p, --pretty                   pretty-print JSON
-a, --accept [component type]  only accepts the specified component type, can be used multiple times
--no-plain-text                do not allow plain-text children    

When the file option is not provided, the JSX string is read from stdin, example:

echo '<MyComponent test />' | react-json-parser --pretty

API usage

parse(code, options)

Parses the provided code string using the supported options:

  • only: Array<string>: only accepts the provided components types, by default accepts any
  • plainText: boolean: allow plain-text children, defaults to true
const { parse } = require('react-json-parser')
const tree = parse(
  '<MyComponent test>Hello <ChildComponent /><OtherChild></MyComponent>',
  {
    only: ['MyComponent', 'ChildComponent'],
    plainText: false,
  }
)
// tree = {type: 'MyComponent', props: {children: [{type: 'ChildComponent'}], test: true}}

License

MIT

FAQs

Package last updated on 07 Dec 2017

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