•json — JSON
•json text reads JSON5, which includes all JSON. JSON5 adds comments, trailing commas, single-quoted strings, unquoted keys, hexadecimal numbers, Infinity and NaN. Objects become keyed vectors. Arrays become vectors. Strings become character vectors. An integer outside the 64-bit range is read as its nearest float: 9223372036854775808 becomes 9.223372037ₑ18. true and false become $t and $f.
•json⁻ Y writes JSON text. Keyed axes become objects. Unkeyed axes become arrays. Character vectors become strings. Keyed entries that hold functions are left out. NaN is written as null.
["fill":v] •json text reads null as v. The fill is converted to its array’s type if the conversion preserves its value: ["fill":0] •json "[1,null,3]" gives [1 0 3]ₓ, and ["fill":0] •json "[true,null]" gives $t $f. If the conversion would change the fill’s value, as with the default NaN beside integers, the array is read as floats. ["fill":v] •json⁻ Y writes v as null. JSON covers the conversions.
Under static kinds, an array of integers is read at the int width, and a value that doesn’t fit raises a DOMAIN error. ["types":R] •json text sets the type of the arrays in named fields: R maps a field’s name to a number of that type, as •csv’s types option does, and every array in a field of that name is read as that type:
•prefs ["kinds":"static"]
(["types":["id":0ₓ₈]] •json "{""id"":[3000000000,7],""n"":[1,2]}").id ⍝ [3000000000 7]ₓ₈
•prefs ["kinds":"dynamic"]Errors: DOMAIN for malformed JSON, with its line and column, and for values that JSON can’t hold: an infinity that isn’t fill, out-of-range floats, rationals that aren’t whole, complex numbers and other functions. Also DOMAIN for a value that can’t be converted to its array’s type unchanged, and for a types entry that names no field holding an array.