@jsonurl/jsonurl

JSON->URL defines a text format for the JSON data model suitable for use within a URL/URI (as described by RFC3986).


Keywords
JSON->URL, json, url, uri, javascript, javascript-library, jsonurl, npm-module, npm-package, rollup-js
License
MIT
Install
npm install @jsonurl/jsonurl@1.1.5

Documentation

JSON→URL

License: MIT NPM version CI Quality Gate Coverage Lines of Code Security Rating Vulnerabilities Maintainability Rating Known Vulnerabilities FOSSA Status Contributor Covenant Conventional Commits project chat

About

RFC8259 describes the JSON data model and interchange format, which is widely used in application-level protocols including RESTful APIs. It is common for applications to request resources via the HTTP POST method, with JSON entities. However, POST is suboptimal for requests which do not modify a resource's state. JSON→URL defines a text format for the JSON data model suitable for use within a URL/URI.

Usage

JSON→URL is available as a commonjs module (suitable for use in Node), ES6 module, or a script that may be used directly in a browser.

NPM install

npm install @jsonurl/jsonurl --save

CJS

const JsonURL = require("@jsonurl/jsonurl");

ES6 (Node + Babel)

import JsonURL from "@jsonurl/jsonurl";

Browser script tag

<script
    src="https://cdn.jsdelivr.net/npm/@jsonurl/jsonurl@1.1.7"
    integrity="sha512-5dbEkq6X5f3wvvLg43JjSbTU90d/UPu8VV+aFmlPnqKgoUZJlq4hmug6EelX7TJgLLsqtm0VMooPMH1Vd1O3Vg=="
    crossorigin="anonymous"></script>

The JavaScript API

Once included, the API is the same for all three.

RunKit: Hello, World!

let value = JsonURL.parse( "(Hello:World!)" );
let string = JsonURL.stringify( value );

If you intend to use JSON→URL inside a browser's address bar then you'll want to enable the AQF (address bar query string friendly) syntax.

RunKit: Hello, Browser Address Bar!

let value = JsonURL.parse( "(Hello:Address Bar!!)",  { AQF: true });
let string = JsonURL.stringify( value,  { AQF: true } );

There are additional options available, but that's all you need to get started.

JSON→URL has no runtime dependencies.

Security

The parser is designed to parse untrusted input. It supports limits on the number of parsed values and depth of nested arrays or objects. When the limit is exceeded an Error is thrown, and reasonable limit values are set by default.

License

FOSSA Status