json5 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.| Name | Version | Size | License | Type | Vulnerabilities |
|---|
JSON5 is a JavaScript library and an extension to the widely-used JSON file format, with the aim of making it easier to write and maintain manually - particularly in the context of configuration files. It's not designed for machine-to-machine communication, for which regular JSON should still be used. The JSON5 Data Interchange Format is a superset of JSON, meaning all valid JSON files will also be valid JSON5 files. This extension introduces several features from ECMAScript 5.1 (ES5) to JSON, and is also a strict subset of ES5, hence all valid JSON5 files will also be valid ES5.
Using JSON5 involves a simple installation process via npm, followed by requiring or importing the library into your JavaScript files. For Node.js, you start by installing it with the command npm install json5. Then, if you're using CommonJS, you can include it in your file using const JSON5 = require('json5'), or if using Modules, use import JSON5 from 'json5'.
With JSON5 successfully imported, you can start utilizing it's API. For instance, JSON5.parse(text[, reviver]) can be used to parse a JSON5 string and construct the JavaScript value or object it describes. As a usage example:
const JSON5 = require('json5')
const jsonString = `{
hello: 'world',
list: ['item1', 'item2', 'item3',]
}`
const jsonObject = JSON5.parse(jsonString)
console.log(jsonObject)
You can also use JSON5 functionalities on a browser. For instance, including it in your HTML file from a CDN like so:
<script src="https://unpkg.com/json5@2/dist/index.min.js"></script>
This will create a global JSON5 variable for use in your client-side JS scripts.
The in-depth documentation for JSON5, including a detailed explanation of the JSON5 format, its API and CLI usage, as well as contribution guidelines, can be found directly on the official GitHub repository (https://github.com/json5/json5). The formal JSON5 Interchange Format specification is also accessible at the external dedicated site (https://spec.json5.org/).