Convert JSON to JSURL and back. Use the "beautify" button to format JSON.
JSURL2 aims to be a drop-in replacement for JSON encoding with better size and time characteristics.
JSURL2 has been designed to be:
<script> tags inside single-quoted JS strings
(unlike JSON); added whitespace can be stripped
rich mode encodes/decodes
Date objects, undefined, NaN
and Infinity
JSON.parse with
JSURL.parse and JSON.stringify with
JSURL.stringify; also parses plain JSON
| Format | Value |
|---|---|
| JSON |
{"name": "John Doé", "age": 42, "user": true, "children":
["Mary", "Bill"]}
|
| JSON + URI encoding |
%7B%22name%22%3A%22John%20Do%C3%A9%22%2C%22age%22%3A42%2C%22user%22%3Atrue%2C%22children%22%3A%5B%22Mary%22%2C%22Bill%22%5D%7D
|
| JSURL2 | (name~John_Doé~age~42~user~~children~!Mary~Bill)~ |
| JSURL2 + URI encoding |
(name~John_Do%C3%A9~age~42~user~~children~!Mary~Bill)~
|
var JSURL = require("jsurl2");
// Options:
// * `rich`: encode Date, `undefined`, `Infinity`
// * `short`: remove optional trailing delimiters
str = JSURL.stringify(obj[, options]);
// Options:
// * `deURI`: remove URI encoding and whitespace
obj = JSURL.parse(str[, options]);
// return `default` instead of throwing on error; options are passed to `parse()`
obj = JSURL.tryParse(str[, default][, options]);
JSURL uses the allowable characters in URI schemes for multiple purposes depending on the location in the result. Some examples:
! starts an array if it is the first character in a
value, but inside a string it is unchanged.
~ and ) are used as end-of-value and
end-of-object delimiters, and are illegal inside encoded values.
* starts a string, but can be left out if the first
string character is a-z. Inside a string, it escapes special
characters.
JSURL has a short mode, which omits unnecessary ending
delimiters, saving a few more bytes.
Since browsers may choose to encode any character with URI escaping,
decoding will work no matter how many encodings happened, if you pass the
deURI: true option to the parser.
Source and full documentation on GitHub.