JSONH is one of the most performant, yet safe, cross programming language, way to pack and unpack generic homogenous collections.
Based on native or shimmed JSON implementation, JSONH is nothing different than a procedure performed right before JSON.stringify(data)
or right after JSON.parse(data)
It is demonstrated that overall performances of JSONH are up to 3 times faster in compression and 2 times in parsing thanks to smaller and simplified nature of the collection/string.
It is also demonstrated that resulting bandwidth size will be incrementally smaller than equivalent JSON operation reaching, in certain cases, down to 30% of original size and without gzip/deflate compression in place.
JSONH is the latest version of json.hpack project and based on JSONDB concept.
schema
argument at the end of all methods in order to parse automatically one or more nested homogenous collectionsUsually a database result set, stored as list of objects where all of them contains the same amount of keys with identical name. This is a basic homogeneous collection example:
[
{"a":"A","b":"B"},
{"a":"C","b":"D"},
{"a":"E","b":"F"}
]
We all have exchange over the network one or more homogenous collections at least once.
JSONH is able to pack the example into [2,"a","b","A","B","C","D","E","F"]
and unpack it into original collection at light speed.
JSON.stringify(data)
and required network bandwidthIf the generic object/data contains one or more homogenous collections, JSONH is suitable for these cases too via pack
and unpack
operations.
Please read the related post to know more.
Every implementation is suitable for the programming language code style and every method supports original JSON signature.
As example the JavaScript version is a global JSONH
object with stringify
, parse
, pack
, and unpack
methods.
The python version is a module similar to json
one with current methods: dump
, dumps
, load
, loads
, pack
, and unpack
.
import jsonh
print(jsonh.dumps(
[{"a": "A", "b": "B"}, {"a": "C", "b": "D"}, {"a": "E", "b": "F"}],
separator = (',',':')
))
The php 5 version is a static class plus some function in order to let developers decide for their favorite stile.
Extra arguments accepted by json_encode
and json_decode
are supported as well.
require_once('JSONH.class.php');
// classic style
jsonh_encode($object); // jsonh_decode($str)
// static public style
JSONH::stringify($object); // JSONH::parse($str);
// singleton style
JSONH()->stringify($object); // JSONH()->parse($str)
pack
on stringify, and unpack
on parse (automated and addressed compression for complex objects)As @garethheyes pointed out by in this post, native JSON.stringify(data)
may produce invalid JavaScript.
Since JSONH aim is not to change native JSON behavior, neither is JSONH a replacement for JSON, all I can suggest is to perform this replacement when and if data could be corrupted:
JSONH.stringify(data).replace(
/\u2028|\u2029/g,
function (m) {
return "\\u202" + (m === "\u2028" ? "8" : "9");
})
This will ensure proper escape for those characters plus performances will be still better thanks to reduced string output size (compared with the equivalent operation performed by JSON.stringify(data)
).
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型