bnclabs / gson

Algorithms on data formats - JSON, CBOR, Collation.
http://prataprc.github.io/jsonsort.io
MIT License
19 stars 8 forks source link

Support for json.Number #8

Closed prataprc closed 7 years ago

prataprc commented 7 years ago

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.

prataprc commented 7 years ago

One of the presumption is that json.Number which is an alias of string should not have any leading whitespace.

prataprc commented 7 years ago

{Value,CBOR,Binary-collate} -> JSON already supports int64 and uint64.