JSON on both platforms, without a library: a strict reader by RFC 8259 on the JVM, and JavaScript's JSON in ClojureScript.
An object reads as a map with keyword keys (unless a :key-fn says otherwise) and an array as a vector. A number reads as a long when it's an integer that fits, and 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 JavaScript's JSON in ClojureScript. An object reads as a map with keyword keys (unless a :key-fn says otherwise) and an array as a vector. A number reads as a long when it's an integer that fits, and 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 returns 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 returns its key, keyword by default.
(write-json x)The JSON text of the value x, as JavaScript writes it:
The JSON text of the value `x`, as JavaScript writes it: - a map as an object, and a vector, a list or a set as an array - a keyword as its name, namespace and all - an instant as its date and time in UTC - a number that isn't finite as null
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 |