bnclabs / gson Goto Github PK
View Code? Open in Web Editor NEWAlgorithms on data formats - JSON, CBOR, Collation.
Home Page: http://prataprc.github.io/jsonsort.io
License: MIT License
Algorithms on data formats - JSON, CBOR, Collation.
Home Page: http://prataprc.github.io/jsonsort.io
License: MIT License
While collating large uint64 and int64 that are outside the bounds of floating point precision for integers, we are self composing a e-notation for such numbers. While doing so, we are supposed to use -1 precision https://golang.org/pkg/strconv/#FormatFloat.
Solution: Use math/big in such cases.
Refer: json5
Let it be a step by step approach highlighting common use case. The challenge though, would be to figure out the common use cases.
travis-ci might bail out if gson-tools is going to randomly thrash gson functions for a long time, find a reasonable time slot and execute gson-tools/make check as part of travis-ci
If golang type json.Number is encounter while transforming
value -> {JSON, CBOR, Binary-collate} treat them in the following manner:
While transforming to JSON:
Do nothing, json.Number is just a string and encode them as JSON string.
While transforming to CBOR:
Check if json.Number is negative by checking for a leading -
. If so encode it as CBOR-int64, else encode it as CBOR-uint64.
While transforming to Binary-collate:
Check if json.Number is negative by checking for a leading -
. Either case, eventually it gets encoded as float64.
Note that collate algorithm transparently treats int, uint, float as
number and make it comparable as same type, as number
.
BenchmarkVal2CollMap 50000 26696 ns/op 16416 B/op 2 allocs/op
BenchmarkVal2CollTyp 10000 174548 ns/op 49250 B/op 6 allocs/op
BenchmarkJson2CollStr 2000 635015 ns/op 1048647 B/op 5 allocs/op
BenchmarkCbor2CollMap 2000 787087 ns/op 1089654 B/op 8 allocs/op
BenchmarkCbor2CollTyp 500 2500523 ns/op 3269067 B/op 25 allocs/op
When key used in a kv storage is shaped as JSON string, then we need some additional support besides what is available in JSON spec
under function value_cbor.go:valtime2cbor()
v.Format(time.RFC3339) // TODO: make rfc3339 as config.
Similarly, under function cbor_value.go:cbor2dtval()
time.Parse(time.RFC3339, item.(string))
JSON-pointer is relative new compared to JSON, so it is good to have an introductory page on JSON-pointer and have references to advanced materials.
Values in int64, uint64 and float64 should be comparable as if they belong to the same type -Number
. Like suggested elsewhere, sorting is a human perception.
Also while converting Binary-collate back to Value, or CBOR, or JSON make sure that precision and accuracy is not lost.
Finally, add test cases to validate them same.
Collating strings is a complex affair. To describe some cases where gson's collation algorthim might fail are:
Refer: collation
Right now val.Tojson() supports the following types:
Both of them are converted to JSON property object. Support for:
As of now, Gson supports following CBOR tagged data types:
tagDateTime
, tagEpoch
, tagPosBignum
, tagNegBignum
,
tagDecimalFraction
, tagBigFloat
, tagCborEnc
, tagRegexp
,
tagCborPrefix
I don't think JSON supports any of them in its present form. If we
can find some innovative way to still represent these tagged data
types within the limited set of JSON types, we can explore further.
Refer: test-vectors
Behind the scenes, support load balancing based on random / moving-average of latency.
This implementation assigns tags 37 and 38 with different meanings than in the document http://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml#tags . Using these tags should be avoided, as CBOR data that makes use of them with the meanings other than specified in that document would make them less interoperable; instead, tags starting from 266 should be used; they're currently not assigned according to that document.
And how it affects different operations.
NewValue(map).ToJson(jsn).Bytes() should return JSON string with keys sorted.
Make this repeatable with future version of gson, and alternate tools similar to gson. Collate the details and numbers that can be consumed via slides, wiki et al.
(a) Replace sync.Pool for objects with simple linked list of objects.
(b) Remove defer() calls that can happen in tight loops.
(a) will have to be tested and benchmarked for
(b) will have to be tested and benchmarked for
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.