└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # Extended Numeric Data Types Compliant with I-JSON 2 | 3 | *I-JSON [[RFC7493](https://tools.ietf.org/html/rfc7493)] defines rules which enable 4 | interoperability between between different implementations. Although useful, 5 | many applications depend on extended numeric data which currently is dealt with in 6 | non-standard ways. This document describes some of the more common variants, 7 | with the goal of eventually establishing some kind of standard, be it de-facto or real.* 8 | 9 | ## The Problem in a Nutshell 10 | The following JSON object highlights some of the issues with JSON numbers: 11 | ```json 12 | { 13 | "giantNumber": 1.4e+9999, 14 | "payMeThis": 26000.33, 15 | "int64Max": 9223372036854775807 16 | } 17 | ``` 18 | - `giantNumber` does not generally parse but could still be usable in certain contexts 19 | - `payMeThis` is probably not meant to be processed by a system based on traditional floating point due to potential *rounding errors* 20 | - `int64Max` parses in all JSON systems but *loses precision* using ECMAScript's `JSON.parse()` 21 | 22 | ## Core Extension Mechanism 23 | Since I-JSON numbers are constrained by IEEE-754 double precision, extended numeric data 24 | types **must** in this specification be enclosed within double quotes, i.e. have JSON String syntax, 25 | permitting basic parsing and serialization of extended data types by *virtually any* JSON tool: 26 | ```json 27 | { 28 | "giantNumber": "1.4e+9999" 29 | } 30 | ``` 31 | 32 | ## Recognizing and Processing Extended Numeric Data Types 33 | A remaining issue is how a JSON parser can know how to recognize and process 34 | extended numeric data types. Fortunately, there are multiple solutions for that. 35 | Below is a *programmatic* variant (here expressed in ECMAScript). relying on 36 | name conventions between sender and receiver: 37 | ```javascript 38 | var obj = JSON.parse('{"giantNumber": "1.4e+9999"}'); 39 | var biggie = new BigNumber(obj.giantNumber); 40 | ``` 41 | In a *declarative* system, data types are usually resolved automatically like in this Java sample: 42 | ```java 43 | class MyObject { 44 | String type; 45 | BigInteger serialNumber; 46 | } 47 | ``` 48 | 49 | ## Extended Numeric Data Types 50 |
| Type | Description | Range | JSON Syntax * |
|---|---|---|---|
| Long | Signed 64-bit integer | -9223372036854775808 to 9223372036854775807 | 0|-?[1-9][0-9]* |
| Ulong | Unsigned 64-bit integer | 0 to 18446744073709551615 | 0|[1-9][0-9]* |
| BigInteger | Arbitrary large signed integer | -Arbitrary to Arbitrary | 0|-?[1-9][0-9]* |
| BigDecimal | Arbitrary large decimal number | -Arbitrary to Arbitrary | -?[0-9]+(\.[0-9]+)?(e(-|\+)[0-9]+)? |
| Money | Decimal number expressing money | -Sufficient to Sufficient | -?[1-9][0-9]*\.[0-9]+ |