All Projects → hua1995116 → easy-json-parse

hua1995116 / easy-json-parse

Licence: MIT license
Parse your json safely and easily.

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to easy-json-parse

android-tao-rest-data-processor
Android REST Data Processor library. Easy to build a REST request, to receive and processing data (XML, JSON, CSV and etc.) from REST requests, file system, assets.
Stars: ✭ 24 (-27.27%)
Mutual labels:  parse
marc4js
A Node.js API for handling MARC
Stars: ✭ 35 (+6.06%)
Mutual labels:  parse
der-parser
BER/DER parser written in pure Rust. Fast, zero-copy, safe.
Stars: ✭ 73 (+121.21%)
Mutual labels:  parse
icc
JavaScript module to parse International Color Consortium (ICC) profiles
Stars: ✭ 37 (+12.12%)
Mutual labels:  parse
HttpUtility
HttpUtility is an open source MIT license project which is helpful in making HTTP requests and returns a decoded object from server. Right now this utility only parses JSON.
Stars: ✭ 28 (-15.15%)
Mutual labels:  parse
libdvbtee
dvbtee: a digital television streamer / parser / service information aggregator supporting various interfaces including telnet CLI & http control
Stars: ✭ 65 (+96.97%)
Mutual labels:  parse
limelight
A php Japanese language text analyzer and parser.
Stars: ✭ 76 (+130.3%)
Mutual labels:  parse
vgprompter
C# library to parse a subset of Ren'Py script syntax
Stars: ✭ 17 (-48.48%)
Mutual labels:  parse
mtgsqlive
MTGJSON build scripts to generate alternative data formats
Stars: ✭ 40 (+21.21%)
Mutual labels:  parse
CROHME extractor
CROHME dataset extractor for OFFLINE-text-recognition task.
Stars: ✭ 77 (+133.33%)
Mutual labels:  parse
Astview
Astview is a graphical viewer for abstract syntax trees
Stars: ✭ 20 (-39.39%)
Mutual labels:  parse
fluent-plugin-http-pull
The input plugin of fluentd to pull log from rest api.
Stars: ✭ 19 (-42.42%)
Mutual labels:  parse
pyhaproxy
Python library to parse haproxy configurations
Stars: ✭ 50 (+51.52%)
Mutual labels:  parse
xml-to-json
Simple API that converts dynamic XML feeds to JSON through a URL or pasting the raw XML data. Made 100% in PHP.
Stars: ✭ 38 (+15.15%)
Mutual labels:  parse
gitsum
parse and summarise git repository history
Stars: ✭ 43 (+30.3%)
Mutual labels:  parse
abstract-syntax-tree
A library for working with abstract syntax trees.
Stars: ✭ 77 (+133.33%)
Mutual labels:  parse
parse-commit-message
(!! moved to tunnckoCore/opensource !! try `parse-commit-message@canary`) Parse, stringify or validate a commit messages that follows Conventional Commits Specification
Stars: ✭ 31 (-6.06%)
Mutual labels:  parse
Splain
small parser to create more interesting language/sentences
Stars: ✭ 15 (-54.55%)
Mutual labels:  parse
Android-Shortify
An Android library used for making an Android application more faster with less amount of code. Shortify for Android provides basic functionalities of view and resource binding, view customization, JSON parsing, AJAX, various readymade dialogs and much more.
Stars: ✭ 21 (-36.36%)
Mutual labels:  parse
astutils
Bare essentials for building abstract syntax trees, and skeleton classes for PLY lexers and parsers.
Stars: ✭ 13 (-60.61%)
Mutual labels:  parse

easy-json-parse

Are you still worried about the long code with try {} catch {}? like this:

const jsonString = 'easy';
let json;

try {
  json = JSON.parse(jsonString);
} catch (e) {
  json = {};
}

console.log(json.xxx);

or

const jsonString = null;
let json;

try {
  json = JSON.parse(jsonString) || {};
} catch (e) {
  json = {};
}

console.log(json.xxx);

Now, no matter whether it is long code or initialization, you don't need to worry.

use easy-json-parse will more easy and safe for try{} catch{}.

Get started

npm i easy-json-parse

case: initialValue

import easyParse from 'easy-json-parse';
const jsonString = 'easy';
const [error, json] = easyParse(jsonString, {initialValue: {}});

console.log(json.xxx); // If json is not exist, will return {} safely.

case: normal

import easyParse from 'easy-json-parse';
const jsonString = '{"easy": "easy"}';
const [error, json] = easyParse(jsonString);

console.log(json.easy); // easy

case: don't need error

import easyParse from 'easy-json-parse';
const jsonString = '{"easy": "easy"}';
const [, json] = easyParse(jsonString);

console.log(json.easy); // easy

Syntax

Parameters

text

the string to parse as JSON

options

options.reviver(optional)

  • if a function, prescribes how the value originally produced by parsing is transformed, before being returned, more info about this param in here

options.initialValue(optional)

  • init value for json.

Returns

Array [error, value]

License

MIT

Copyright (c) 2019 蓝色的秋风

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].