npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lenientjsonjs

v1.0.0

Published

A lenient JSON parser for JS (GSON-compatible)

Downloads

17

Readme

lenientjsonjs

A small library for JS containing a GSON lenient-compatible JSON parser and stringifier. I personally needed this for Minecraft JSON parsing in other languages.

Reference

GSON.parse(json (string), [strict (bool)])

json: the string to parse
strict: whether or not to use strict parsing. Default value is false.

Parses the requested JSON and returns the parsed object. Throws Errors if an error occurs during parsing.

If "strict" is disabled, GSON's "JsonReader" lenient parsing is enabled.

For reference, this is the current list of supported concepts:

  • Streams that start with the non-execute prefix, ")]}'\n".
  • Numbers may be NaNs or infinities.
  • End of line comments starting with // or # and ending with a newline character.
  • C-style comments starting with /* and ending with */. Such comments may not be nested.
  • Names that are unquoted or 'single quoted'.
  • Strings that are unquoted or 'single quoted'.
  • Array elements separated by ; instead of ,.
  • Names and values separated by = or => instead of :.
  • Name/value pairs separated by ; instead of ,.

These concepts are NOT supported currently, as personally I did not need them:

  • Unnecessary array separators. These are interpreted as if null was the omitted value.
  • Streams that include multiple top-level values. With strict parsing, each stream must contain exactly one top-level value.
  • Top-level values of any type. With strict parsing, the top-level value must be an object or an array.

GSON.stringify(obj (any), [options (dictionary OR boolean)])

obj: object to stringify
options: either a property bag of options to use in the stringification process, false, or left out. Default value is undefined. Setting to false enables some very loose leniency (unquoted/single-quoted keys/strings & NaNs/infinites).
valid properties:
keyPairSeparator (string): the separator string used between key/value pairs. Default is :
arraySeparator (string): the separator string used between array elements. Default is ,
allowNaNInfinite (bool): whether or not NaNs and Infinites will be stringified as-is. Default is false (outputs nulls).
unquotedKeys (bool): whether or not keys in key/value pairs can be unquoted, if possible. Default is false.
unquotedStrings (bool): whether or not string values can be unquoted, if possible. Default is false.
preferSingleQuotedKeys (bool): whether or not keys in key/value pairs can use the single quote character, if possible. Default is false.
preferSingleQuotedStrings (bool): whether or not string values can use the single quote character, if possible. Default is false.

Returns a string representation of the object passed to it.

License

MIT; go nuts and use for whatever purpose. I'd like a linkback, but not required.