![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Json Escape use escape character in string to store types that normally not allowed in JSON
asc character 0x1b is used for the escaping
// import JsonEsc from 'jsonesc';
const JsonEsc = require('jsonesc').default;
JsonEsc.stringify( [
NaN,
-Infinity,
new Date(),
new Uint8Array([1,2,3,4]),
undefined
], 1);
// returns:
[
"\u001bNaN",
"\u001b-Inf",
"\u001bDate:2018-02-07T19:07:18.207Z",
"\u001bBin:wFg{A",
"\u001b"
]
JsonEsc allows additional data types to be serialized in JSON, such as binary date (Uint8Array) and Date, while still keeps the verbose nature of JSON.
The output string is still a 100% valid JSON, and compatible with any JSON editing/parsing tool or library. This makes JsonEsc much easier to debug and trouble shoot than binary formats like BSON and MsgPack
Modern browsers and nodejs are hightly optimized for JSON. This allows JsonEsc to be encoded and decoded faster than the other 2 formats in most of the cases.
Benchmark with sample data on Chrome 67, Firefox59, Edge 42
Time are all in ms, smaller is better
Chrome Encode | Chrome Decode | Firefox Encode | Firefox Decode | Edge Encode | Edge Decode | |
---|---|---|---|---|---|---|
JsonEsc | 0.1161 | 0.1606 | 0.1394 | 0.1553 | 0.0899 | 0.0753 |
MsgPack | 0.2465 | 0.1191 | 0.8663 | 0.2313 | 0.5752 | 0.2653 |
BSON | 0.1255 | 0.1170 | 0.3634 | 0.6124 | 0.27005 | 0.37705 |
JsonEsc.stringify(inpt:any, space?:number, sortKeys?:boolean = false);
JsonEsc.parse(inpt:string);
JsonEsc's register API make it really simple to add custom type into json encoding/decoding
// custom type
class MyClass {
constructor(str) {
this.myStr = str;
}
}
let myJson = new JsonEsc();
myJson.register('My', MyClass,
// custom encoder
(obj) => obj.myStr,
// custom decoder
(str) => new MyClass(str)
);
myJson.stringify(new MyClass("hello"));
// "\u001bMy:hello"
JsonEsc use Base93 to encode binary data, it's more compact than Base64.
If you still prefer Base64, just use these lines to register Uint8Array with a base64 encoder/decoder
const JsonEsc = require('jsonesc').default;
const Base64 = require("base64-js");
let myJson = new JsonEsc();
myJson.register('B64', Uint8Array,
(uint8arr) => Base64.fromByteArray(uint8arr),
(str) => new Uint8Array(Base64.toByteArray(str.substr(5)))
);
myJson.stringify({ binary:new Uint8Array([1,2,3,4])});
// {"binary":"\u001bB64:AQIDBA=="}
FAQs
Json Escape
The npm package jsonesc receives a total of 7 weekly downloads. As such, jsonesc popularity was classified as not popular.
We found that jsonesc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.