API for clojure.data.json - data.json 2.5.1-SNAPSHOT (in development)

by Stuart Sierra

Full namespace name: clojure.data.json

Overview

JavaScript Object Notation (JSON) parser/generator.
See http://www.json.org/

Protocols



JSONWriter

Protocol

    Known implementations: clojure.lang.BigInt, clojure.lang.Named, clojure.lang.Ratio, java.lang.Boolean, java.lang.Byte, java.lang.CharSequence, java.lang.Double, java.lang.Float, java.lang.Integer, java.lang.Long, java.lang.Short, java.math.BigDecimal, java.math.BigInteger, java.sql.Date, java.time.Instant, java.util.Collection, java.util.concurrent.atomic.AtomicInteger, java.util.concurrent.atomic.AtomicLong, java.util.Date, java.util.Map, java.util.UUID, nil, Object
    

-write

function
Usage: (-write object out options)
Print object to Appendable out as JSON

      
      
      
    
Source

Types



ReaderPBR

type

    Fields: [rdr]
Protocols:
Interfaces: clojure.data.json.InternalPBR


StringPBR

type

    Fields: [s pos len]
Protocols:
Interfaces: clojure.data.json.InternalPBR

Public Variables and Functions



->ReaderPBR

function
Usage: (->ReaderPBR rdr)
Positional factory function for class clojure.data.json.ReaderPBR.

    
    
    Source
  


->StringPBR

function
Usage: (->StringPBR s pos len)
Positional factory function for class clojure.data.json.StringPBR.

    
    
    Source
  


json-str

function
Usage: (json-str x & options)
DEPRECATED; replaced by 'write-str'.

Converts x to a JSON-formatted string.

Valid options are:
  :escape-unicode false
      to turn of \uXXXX escapes of Unicode characters.

    
    
    Source
  


on-extra-throw

function
Usage: (on-extra-throw val rdr)
Pass as :extra-data-fn to `read` or `read-str` to throw if data is found
after the first object.

    
    
    Source
  


on-extra-throw-remaining

function
Usage: (on-extra-throw-remaining val rdr)
Pass as :extra-data-fn to `read` or `read-str` to throw if data is found
after the first object and return the remaining data in ex-data :remaining.

    
    
    Source
  


pprint

function
Usage: (pprint x & {:as options})
Pretty-prints JSON representation of x to *out*. Options are the same
as for write except :value-fn and :indent, which are not supported.

    
    
    Source
  


pprint-json

function
Usage: (pprint-json x & options)
DEPRECATED; replaced by 'pprint'.

Pretty-prints JSON representation of x to *out*.

Valid options are:
  :escape-unicode false
      to turn off \uXXXX escapes of Unicode characters.

    
    
    Source
  


print-json

function
Usage: (print-json x & options)
DEPRECATED; replaced by 'write' to *out*.

Write JSON-formatted output to *out*.

Valid options are:
  :escape-unicode false
      to turn off \uXXXX escapes of Unicode characters.

    
    
    Source
  


read

function
Usage: (read reader & {:as options})
Reads a single item of JSON data from a java.io.Reader.

If you wish to repeatedly read items from the same reader, you must
supply a PushbackReader and reuse it on subsequent calls.

Options are key-value pairs, valid options are:

   :eof-error? boolean

      If true (default) will throw exception if the stream is empty.

   :eof-value Object

      Object to return if the stream is empty and eof-error? is
      false. Default is nil.

   :bigdec boolean

      If true use BigDecimal for decimal numbers instead of Double.
      Default is false.

   :key-fn function

      Single-argument function called on JSON property names; return
      value will replace the property names in the output. Default
      is clojure.core/identity, use clojure.core/keyword to get
      keyword properties.

   :value-fn function

      Function to transform values in maps ("objects" in JSON) in
      the output. For each JSON property, value-fn is called with
      two arguments: the property name (transformed by key-fn) and
      the value. The return value of value-fn will replace the value
      in the output. If value-fn returns itself, the property will
      be omitted from the output. The default value-fn returns the
      value unchanged. This option does not apply to non-map
      collections.

   :extra-data-fn function

     If :extra-data-fn is not nil, then the reader will be checked
     for extra data after the read. If found, the extra-data-fn will
     be invoked with the read value and the reader. The result of
     the extra-data-fn will be returned.

    
    
    Source
  


read-json

function
Usage: (read-json input)
       (read-json input keywordize?)
       (read-json input keywordize? eof-error? eof-value)
DEPRECATED; replaced by read-str.

Reads one JSON value from input String or Reader. If keywordize? is
true (default), object keys will be converted to keywords. If
eof-error? is true (default), empty input will throw an
EOFException; if false EOF will return eof-value.

    
    
    Source
  


read-str

function
Usage: (read-str string & {:as options})
Reads one JSON value from input String. Options are the same as for
read.

    
    
    Source
  


write

function
Usage: (write x writer & {:as options})
Write JSON-formatted output to a java.io.Writer. Options are
key-value pairs, valid options are:

 :escape-unicode boolean

    If true (default) non-ASCII characters are escaped as \uXXXX

 :escape-js-separators boolean

    If true (default) the Unicode characters U+2028 and U+2029 will
    be escaped as \u2028 and \u2029 even if :escape-unicode is
    false. (These two characters are valid in pure JSON but are not
    valid in JavaScript strings.)

 :escape-slash boolean

    If true (default) the slash / is escaped as \/

 :sql-date-converter function

    Single-argument function used to convert a java.sql.Date to
    a java.time.Instant. As java.sql.Date does not have a
    time-component (which is required by java.time.Instant), it needs
    to be computed. The default implementation, `default-sql-date->instant-fn`
    uses
    ```
       (.toInstant (.atStartOfDay (.toLocalDate sql-date) (java.time.ZoneId/systemDefault)))
    ```

 :date-formatter

     A java.time.DateTimeFormatter instance, defaults to DateTimeFormatter/ISO_INSTANT

 :key-fn function

     Single-argument function called on map keys; return value will
     replace the property names in the output. Must return a
     string. Default calls clojure.core/name on symbols and
     keywords and clojure.core/str on everything else.

 :value-fn function

     Function to transform values in maps before writing. For each
     key-value pair in an input map, called with two arguments: the
     key (BEFORE transformation by key-fn) and the value. The
     return value of value-fn will replace the value in the output.
     If the return value is a number, boolean, string, or nil it
     will be included literally in the output. If the return value
     is a non-map collection, it will be processed recursively. If
     the return value is a map, it will be processed recursively,
     calling value-fn again on its key-value pairs. If value-fn
     returns itself, the key-value pair will be omitted from the
     output. This option does not apply to non-map collections.

  :default-write-fn function

     Function to handle types which are unknown to data.json. Defaults
     to a function which throws an exception. Expects to be called with
     three args, the value to be serialized, the output stream, and the
     options map.

 :indent boolean

     If true, indent json while writing (default = false).

    
    
    Source
  


write-json

function
Usage: (write-json x out escape-unicode?)
DEPRECATED; replaced by 'write'.

Print object to PrintWriter out as JSON

    
    
    Source
  


write-str

function
Usage: (write-str x & {:as options})
Converts x to a JSON-formatted string. Options are the same as
write.

    
    
    Source
  
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.