JSON Transform Tests

JSON Transform Tests

Appendix to: Parsing JSON is a Minefield

2016-10-17 22:00:00
  1. Numbers
  2. Objects
  3. Strings

Numbers

Serialized 1.0 Double
Freddy 1.0 Double
MyJSON 1.0 NSNumber - double
JSONSerialization 1.0 NSNumber - double
JSONKit 1.0 NSNumber - double
Lua JSON 20160728.17 1 number
Lua dkjson 1 number
Ruby 1.0 Float
Rust 1.12.0 / json 0.10.2 1.0 Number

Serialized 1.000000000000000005 Double
Freddy 1.0 Double
MyJSON 1.0 NSNumber - double
JSONSerialization 1.0 NSNumber - double
JSONKit 1.0 NSNumber - double
Lua JSON 20160728.17 1 number
Lua dkjson 1 number
Ruby 1.0 Float
Rust 1.12.0 / json 0.10.2 1.000000000000000005 Number

Serialized 1E-999 Double
Freddy 1E-999 String
MyJSON 0 NSNumber - double
JSONSerialization Error
JSONKit Error
Lua JSON 20160728.17 0 number
Lua dkjson 0 number
Ruby 0.0 Float
Rust 1.12.0 / json 0.10.2 1E-999 Number

Serialized 1E6 Double
Freddy 1000000.0 Double
MyJSON 1000000 NSNumber - double
JSONSerialization 1000000.0 NSNumber - double
JSONKit 1000000.0 NSNumber - double
Lua JSON 20160728.17 1000000 number
Lua dkjson 1000000 number
Ruby 1000000.0 Float
Rust 1.12.0 / json 0.10.2 1E6 Number

Serialized 1000000000000000 Int
Freddy 1000000000000000 Int
MyJSON 1000000000000000 NSNumber - long long
JSONSerialization 1000000000000000 NSNumber - long long
JSONKit 1000000000000000 NSNumber - long long
Lua JSON 20160728.17 1e+15 number
Lua dkjson 1e+15 number
Ruby 1000000000000000 Fixnum
Rust 1.12.0 / json 0.10.2 1000000000000000 Number

Serialized 10000000000000000999 Int
Freddy 10000000000000000999 String
MyJSON 10000000000000000999 String
JSONSerialization 10000000000000000999 NSDecimalNumber - double
JSONKit 10000000000000000999 unsigned long long
cJSON 10000000000000002048 double
Lua JSON 20160728.17 1e+19 number
Lua dkjson 1e+19 number
Lua dkjson 10000000000000000999 Bignum
Rust 1.12.0 / json 0.10.2 10000000000000000999 Number

Objects

Objects - Key NFC, key NFD

Serialized {"C3A9:"NFC","65CC81":"NFD"} {"é":"NFC","é":"NFD"}
Freddy {"65CC81":"NFD"}
MyJSON {"65CC81":"NFD"}
Swift JSONSerialization {"65CC81":"NFD"}
Obj-C NSJSONSerialization {"C3A9:"NFC","65CC81":"NFD"}
Obj-C SBJSON {"C3A9:"NFC","65CC81":"NFD"}
JSONKit {"C3A9:"NFC","65CC81":"NFD"}
C cJSON {"C3A9:"NFC","65CC81":"NFD"}
Go {"C3A9:"NFC","65CC81":"NFD"}
Python 3.5.2 {"C3A9:"NFC","65CC81":"NFD"}
JavaScript {"C3A9:"NFC","65CC81":"NFD"}
R rjson {"C3A9:"NFC","65CC81":"NFD"}
R jsonlite {"C3A9:"NFC","65CC81":"NFD"}
Lua JSON 20160728.17 {"C3A9:"NFC","65CC81":"NFD"}
Lua dkjson {"C3A9:"NFC","65CC81":"NFD"}
Ruby {"C3A9:"NFC","65CC81":"NFD"}
Rust 1.12.0 / json 0.10.2 {"C3A9:"NFC","65CC81":"NFD"}

Objects - Key NFD, key NFC

Serialized {"65CC81":"NFD","C3A9:"NFC"} {"é":"NFD","é":"NFC"}
Freddy {"C3A9":"NFC"}
MyJSON {"C3A9":"NFC"}
Swift JSONSerialization {"C3A9":"NFC"}
Obj-C NSJSONSerialization {"C3A9:"NFC","65CC81":"NFD"}
Obj-C SBJSON {"C3A9:"NFC","65CC81":"NFD"}
JSONKit {"C3A9:"NFC","65CC81":"NFD"}
C cJSON {"C3A9:"NFC","65CC81":"NFD"}
Go {"65CC81":"NFD","C3A9:"NFC"}
Python 2 {"65CC81":"NFD","C3A9:"NFC"}
Python 3 {"C3A9:"NFC","65CC81":"NFD"}
JavaScript {"65CC81":"NFD","C3A9:"NFC"}
R rjson {"65CC81":"NFD","C3A9:"NFC"}
R jsonlite {"65CC81":"NFD","C3A9:"NFC"}
Lua JSON 20160728.17 {"C3A9:"NFC","65CC81":"NFD"}
Lua dkjson {"C3A9:"NFC","65CC81":"NFD"}
Ruby {"65CC81":"NFD","C3A9:"NFC"}
Rust 1.12.0 / json 0.10.2 {"65CC81":"NFD","C3A9:"NFC"}

Objects - Same keys, different values

Serialized {"a":1,"a":2}
Freddy {"a":2}
MyJSON {"a":2}
Swift JSONSerialization {"a":1}
Obj-C NSJSONSerialization {"a":1}
Obj-C SBJSON {"a":2}
JSONKit {"a":2}
C cJSON {"a":1,"a":2}
Go {"a":2}
Python 2 {"a":2}
Python 3 {"a":2}
JavaScript {"a":2}
R rjson {"a":1,"a":2}
R jsonlite {"a":1,"a":2}
Lua JSON 20160728.17 {"a":1,"a":2}
Lua dkjson {"a":2}
Ruby {"a":2}
Rust 1.12.0 / json 0.10.2 {"a":2}

Objects - Same keys, same values

Serialized {"a":1,"a":1}
Freddy {"a":1}
MyJSON {"a":1}
Swift JSONSerialization {"a":1}
Obj-C NSJSONSerialization {"a":1}
Obj-C SBJSON {"a":1}
JSONKit {"a":1}
C cJSON {"a":1,"a":1}
Go {"a":1}
Python 2 {"a":1}
Python 3 {"a":1}
JavaScript {"a":1}
R rjson {"a":1,"a":1}
R jsonlite {"a":1,"a":1}
Lua JSON 20160728.17 {"a":1,"a":1}
Lua dkjson {"a":1}
Ruby {"a":1}
Rust 1.12.0 / json 0.10.2 {"a":1}

Objects - Same keys, values 0 and -0

Serialized {"a":0,"a":-0}
Freddy {"a":0}
MyJSON {"a":0}
Swift JSONSerialization
Obj-C NSJSONSerialization {"a":0}
Obj-C SBJSON {"a":0}
JSONKit {"a":-0}
C cJSON {"a":0, "a":0}
Go {"a":-0}
Python 2 {"a":0}
Python 3 {"a":0}
JavaScript {"a":-0}
R rjson {"a":0, "a":0}
R jsonlite {"a":0, "a":0}
Lua JSON 20160728.17 {"a":-0}
Lua dkjson {"a":-0}
Ruby {"a":0}
Rust 1.12.0 / json 0.10.2 {"a":0}

Strings

String - String with escaped NULL

Serialized ["A\u0000B"]
Freddy ["A"]
MyJSON ["A00B"]
Swift JSONSerialization ["A00B"]
Obj-C NSJSONSerialization ["A00B"]
Obj-C SBJSON ["A00B"]
JSONKit nil
C cJSON NULL
Go ["A00B"]
Python 2 ["A00B"]
Python 3 ["A00B"]
JavaScript ["A00B"]
Lua JSON 20160728.17 ["A00B"]
Lua dkjson ["A00B"]
Ruby ["A00B"]
Rust 1.12.0 / json 0.10.2 ["A00B"]

String - 1 escaped invalid codepoint

Serialized ["\uD800"]
Freddy UnicodeEscapeInvalid(2)
MyJSON ["EFBFBD"] �, U+FFFD REPLACEMENT CHARACTER
Swift JSONSerialization Error Domain=NSCocoaErrorDomain, Code=3840, "Unexpected end of file during string parse (expected low-surrogate code point but did not find one)."
Obj-C NSJSONSerialization Error Domain=NSCocoaErrorDomain, Code=3840, "Unexpected end of file during string parse (expected low-surrogate code point but did not find one)."
Obj-C SBJSON WaitingForData - a partial document was found and more data is required to complete it
JSONKit Error Domain=JKErrorDomain Code=-1 "Required a second \u Unicode escape sequence following a surrogate \u Unicode escape sequence."
C cJSON NULL
Go ["EFBFBD"] �, U+FFFD REPLACEMENT CHARACTER
Python 2 ["\uD800"]
Python 3 ["\uD800"]
JavaScript ["EFBFBD"] �, U+FFFD REPLACEMENT CHARACTER
R rjson ["EDA080"]
R jsonlite ["?"]
Lua JSON 20160728.17 ["?"]
Lua dkjson ["EDA080"]
Ruby nil
Rust 1.12.0 / json 0.10.2 UnexpectedCharacter { ch: '\"', line: 1, column: 9 }

String - 2 escaped invalid codepoints

Serialized ["\uD800\uD800"]
Freddy UnicodeEscapeInvalid(2)
MyJSON ["EFBFBDEFBFBD"] ["��"]
Swift JSONSerialization Error Domain=NSCocoaErrorDomain Code=3840 "Invalid surrogate pair in unicode escape sequence around character 10."
Obj-C NSJSONSerialization Error Domain=NSCocoaErrorDomain Code=3840 "Invalid surrogate pair in unicode escape sequence around character 10."
Obj-C SBJSON Error Domain=org.sbjson.parser Code=3 "Invalid low character in surrogate pair at index 14"
JSONKit Error Domain=JKErrorDomain Code=-1 "Illegal \u Unicode escape sequence."
C cJSON NULL
Go ["EFBFBDEFBFBD"] ["��"]
Python 2 ["\ud800\ud800"]
Python 3 ["\ud800\ud800"]
JavaScript ["EFBFBDEFBFBD"] ["��"]
R rjson ["EDA080EDA080"]
R jsonlite ["\U00010000"]
Lua JSON 20160728.17 ["??"]
Lua dkjson ["EDA080EDA080"]
Ruby ["F0908080"] ??
Rust 1.12.0 / json 0.10.2 FailedUtf8Parsing

String - 3 escaped invalid codepoints

Serialized ["\uD800\uD800\uD800"]
Freddy UnicodeEscapeInvalid(2)
MyJSON ["EFBFBDEFBFBDEFBFBD"] ["���"]
Swift JSONSerialization Error Domain=NSCocoaErrorDomain Code=3840 "Invalid surrogate pair in unicode escape sequence around character 10."
Obj-C NSJSONSerialization Error Domain=NSCocoaErrorDomain Code=3840 "Invalid surrogate pair in unicode escape sequence around character 10."
Obj-C SBJSON Error Domain=org.sbjson.parser Code=3 "Invalid low character in surrogate pair at index 14"
JSONKit Error Domain=JKErrorDomain Code=-1 "Illegal \u Unicode escape sequence."
C cJSON NULL
Go ["EFBFBDEFBFBDEFBFBD"] ["���"]
Python 2 ["\ud800\ud800\ud800"]
Python 3 ["\ud800\ud800\ud800"]
JavaScript ["EFBFBDEFBFBDEFBFBD"] ["���"]
R rjson ["EDA080EDA080EDA080"]
R jsonlite ["\U00010000?"]
Lua JSON 20160728.17 ["???"]
Lua dkjson ["EDA080EDA080EDA080"]
Ruby nil
Rust 1.12.0 / json 0.10.2 FailedUtf8Parsing

String - 1 invalid codepoint

Serialized ["EDA080"]
Freddy UnicodeEscapeInvalid(1)
MyJSON cannotBuildStringFromData(5)
Swift JSONSerialization Error Domain=NSCocoaErrorDomain Code=3840 "Unable to convert data to string around character 1."
Obj-C NSJSONSerialization Error Domain=NSCocoaErrorDomain Code=3840 "Unable to convert data to string around character 1."
Obj-C SBJSON CRASH
JSONKit Error Domain=JKErrorDomain Code=-1 "Illegal UTF8 sequence found in "" string."
C cJSON ["EDA080"]
Go ["EFBFBDEFBFBDEFBFBD"] ���, U+FFFD REPLACEMENT CHARACTER
Python 2 ["\ud800"]
Python 3 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 2: invalid continuation byt
JavaScript ["EFBFBDEFBFBDEFBFBD"] ���, U+FFFD REPLACEMENT CHARACTER
R rjson ["EDA080"]
R jsonlite ["EDA080"]
Lua JSON 20160728.17 ["EDA080"]
Lua dkjson ["EDA080"]
Ruby ["EDA080"]
Rust 1.12.0 / json 0.10.2 InvalidData - stream did not contain valid UTF-8

String - 2 invalid codepoints

Serialized ["EDA080EDA080"]
Freddy UnicodeEscapeInvalid(1)
MyJSON cannotBuildStringFromData(8)
Swift JSONSerialization Error Domain=NSCocoaErrorDomain Code=3840 "Unable to convert data to string around character 1."
Obj-C NSJSONSerialization Error Domain=NSCocoaErrorDomain Code=3840 "Unable to convert data to string around character 1."
Obj-C SBJSON
JSONKit Error Domain=JKErrorDomain Code=-1 "Illegal UTF8 sequence found in "" string."
C cJSON ["EDA080EDA080"]
Go [������]
Python 2 ["\ud800\ud800"]
Python 3 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 2: invalid continuation byte
JavaScript ["������"]
R rjson ["EDA080EDA080"]
R jsonlite ["EDA080EDA080"]
Lua JSON 20160728.17 ["EDA080EDA080"]
Lua dkjson ["EDA080EDA080"]
Ruby ["EDA080EDA080"]
Rust 1.12.0 / json 0.10.2 InvalidData - stream did not contain valid UTF-8

String - 3 invalid codepoints

Serialized ["EDA080EDA080EDA080"]
Freddy UnicodeEscapeInvalid(1)
MyJSON cannotBuildStringFromData(11)
Swift JSONSerialization Error Domain=NSCocoaErrorDomain Code=3840 "Unable to convert data to string around character 1."
Obj-C NSJSONSerialization Error Domain=NSCocoaErrorDomain Code=3840 "Unable to convert data to string around character 1."
Obj-C SBJSON CRASH
JSONKit Error Domain=JKErrorDomain Code=-1 "Illegal UTF8 sequence found in "" string."
C cJSON ["EDA080EDA080EDA080"]
Go ["���������"]
Python 2 ["\ud800\ud800\ud800"]
Python 3 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 2: invalid continuation byte
JavaScript ["���������"]
R rjson ["EDA080EDA080EDA080"]
R jsonlite ["EDA080EDA080EDA080"]
Lua JSON 20160728.17 ["EDA080EDA080EDA080"]
Lua dkjson ["EDA080EDA080EDA080"]
Ruby ["EDA080EDA080EDA080"] nil
Rust 1.12.0 / json 0.10.2 InvalidData - stream did not contain valid UTF-8