Components and utilities for the modern web
Javascript Utilities

parseJSON

parseJSON is a utility that lets you do two things in a single line:

  1. Specify the JSON content to parse.
  2. And if that fails, specify a default value.

Installation

First, make sure you install Splendid UI.

npm install splendid-ui

Then import parseJSON into your project.

import { parseJSON } from 'splendid-ui/utils'

Usage

When you use parseJSON, just specify the JSON you wanto parse and a defaultValue you wish to provide.

const value = parseJSON(json, defaultValue)

// If JSON is valid value will be === JSON data
// If JSON is invalid, value will be === defaultValue

That’s all you need to know to use parseJSON!

Like what you're seeing?

I'm on a quest to make web development extremely easy — by building components and utilities that will help all of us build better apps at a much faster pace.

I'd like to send you an update when I release something new in Splendid UI. If you want to be updated, please leave your email address below.

Powered by Buttondown