![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
json5
Advanced tools
Package description
The json5 npm package is a JSON parser and serializer that allows for comments, trailing commas, single quotes, and more. It is designed to be a more user-friendly and flexible version of JSON.
Parsing JSON5 Strings
This feature allows you to parse JSON5 strings into JavaScript objects. It supports comments, single quotes, and additional syntax that is not available in standard JSON.
{"parse": "JSON5.parse('{/*comment*/\"key\": \"value\"}')"}
Stringifying JavaScript Objects
This feature converts JavaScript objects into JSON5 strings. It can include features like trailing commas and unquoted keys, making the output more human-readable.
{"stringify": "JSON5.stringify({key: 'value'}, null, 2)"}
YAML is a human-friendly data serialization standard that can be used as an alternative to JSON. It supports comments, complex data structures, and is often used in configuration files. It is more flexible than JSON5 but uses a different syntax.
TOML is a configuration file format that is easy to read due to its clear semantics. It is similar to JSON5 in that it aims to be more user-friendly, but it has its own syntax and is often used in applications where configuration files are written and maintained by humans.
Changelog
v0.0.1 [[code][c0.0.1], [diff][d0.0.1]]
This was the first implementation of this JSON5 parser.
Support unquoted object keys, including reserved words. Unicode characters and escape sequences sequences aren't yet supported.
Support single-quoted strings.
Support multi-line strings.
Support trailing commas in arrays and objects.
Support comments, both inline and block.
Readme
JSON is strict. Keys need to be quoted; strings can only be double-quoted; objects and arrays can't have trailing commas; and comments aren't allowed.
Using such a strict subset of "JavaScript object notation" was likely for the best at the time, but with modern ECMAScript 5 engines like V8 in Chrome and Node, these limitations are cumbersome.
JSON5 does for JSON what ES5 did for ES3. It also is to regular ES5 what JSON was to ES3 — a pure subset.
This module provides a replacement for ES5's native JSON.parse()
method that
understands these additions. The parser is based directly off of Douglas
Crockford's json_parse.js, which avoids eval()
and validates input as it
parses it, making it secure and safe to use today.
Object keys don't need to be quoted if they contain no special characters. Yes, even reserved keywords are valid unquoted keys in ES5.
[TODO: Unicode characters and escape sequences aren't yet supported in unquoted keys.]
Strings can be single-quoted.
Strings can be multi-line; just prefix the newline with a backslash.
Objects and arrays can have trailing commas.
Both inline (single-line) and block (multi-line) comments are allowed.
[IDEA: Allow octal and hexadecimal numbers.]
{
foo: 'bar',
while: true,
this: 'is a\
multi-line string',
// this is an inline comment
here: 'is another', // inline comment
/* this is a block comment
it continues on another line */
finally: 'a trailing comma',
oh: [
'we shouldn\'t forget',
'arrays can have',
'trailing commas too',
],
}
Via npm on Node:
npm install json5
var JSON5 = require('json5');
Or in the browser (adds the JSON5
object to the global namespace):
<script src="json5.js"></script>
var obj = JSON5.parse('{unquoted:"key",trailing:"comma",}');
var str = JSON5.stringify(obj);
console.log(obj);
console.log(str);
JSON5.stringify()
is currently aliased to the native JSON.stringify()
in
order for the output to be fully compatible with all JSON parsers today.
git clone git://github.com/aseemk/json5.git
cd json5
npm link
npm test
Feel free to file issues and submit pull requests — contributions are welcome.
If you submit a pull request, please be sure to add or update corresponding
test cases, and ensure that npm test
continues to pass.
MIT License. © 2012 Aseem Kishore.
Michael Bolin independently arrived at and published some of these same ideas with awesome explanations and detail. Recommended reading: Suggested Improvements to JSON
Douglas Crockford of course designed and built JSON, but his state machine diagrams on the JSON website, as cheesy as it may sound, gave me motivation and confidence that building a new parser to implement these ideas this was within my reach! This code is also modeled directly off of Doug's open-source json_parse.js parser. I'm super grateful for that clean and well-documented code.
FAQs
JSON for Humans
The npm package json5 receives a total of 58,177,227 weekly downloads. As such, json5 popularity was classified as popular.
We found that json5 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.