JSON on both platforms, without a library: a strict reader by RFC 8259 on the JVM, and the JSON of JavaScript in ClojureScript.
An object reads as a map with keyword keys, unless a :key-fn says otherwise, an array as a vector, and a number as a long when it's an integer that fits, or else as a double. On the JVM, a longer integer reads as a bigint, and read-json returns nil for a text with an integer of more than max-digits digits. In JavaScript every number is a double, so an integer past 2^53 loses its last digits there.
JSON on both platforms, without a library: a strict reader by RFC 8259 on the JVM, and the JSON of JavaScript in ClojureScript. An object reads as a map with keyword keys, unless a :key-fn says otherwise, an array as a vector, and a number as a long when it's an integer that fits, or else as a double. On the JVM, a longer integer reads as a bigint, and read-json returns nil for a text with an integer of more than max-digits digits. In JavaScript every number is a double, so an integer past 2^53 loses its last digits there.
How deep the arrays and objects of a JSON text may nest, so that a hostile text can't use up the stack.
How deep the arrays and objects of a JSON text may nest, so that a hostile text can't use up the stack.
How many digits an integer of a JSON text may have on the JVM, where the time to read a bigint grows with the square of its digits.
A decimal reads as a double, in a time that grows with its length alone, so it has no such limit. Nor does a number in ClojureScript, where JSON.parse reads every number as a double.
How many digits an integer of a JSON text may have on the JVM, where the time to read a bigint grows with the square of its digits. A decimal reads as a double, in a time that grows with its length alone, so it has no such limit. Nor does a number in ClojureScript, where JSON.parse reads every number as a double.
(read-json s)(read-json s {:keys [key-fn] :or {key-fn keyword} :as opts})The value of the JSON text s, read by the opts below, or nil when s
isn't JSON, nests deeper than max-depth or, on the JVM, has an integer of
more than max-digits digits.
The opts are :key-fn, a function of the name of each member of an
object that gives its key, keyword by default.
The value of the JSON text `s`, read by the `opts` below, or nil when `s` isn't JSON, nests deeper than max-depth or, on the JVM, has an integer of more than max-digits digits. The `opts` are :key-fn, a function of the name of each member of an object that gives its key, keyword by default.
(write-json x)The JSON text of the value x: a map as an object, with keywords as
their names, namespace and all, a vector, a list or a set as an array,
an instant as its date and time in UTC, and a number that isn't finite
as null, as JavaScript writes it.
The JSON text of the value `x`: a map as an object, with keywords as their names, namespace and all, a vector, a list or a set as an array, an instant as its date and time in UTC, and a number that isn't finite as null, as JavaScript writes it.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |