### Custom Key Conversion on Read Source: https://github.com/clojure/data.json/blob/master/README.md Use the :key-fn option with json/read-str to transform map keys during parsing. This example converts string keys to Clojure keywords. ```clojure (json/read-str "{\"a\":1,\"b\":2}" :key-fn keyword) ``` -------------------------------- ### Custom Key Conversion on Write Source: https://github.com/clojure/data.json/blob/master/README.md Use the :key-fn option with json/write-str to transform map keys before serialization. This example converts Clojure keywords to uppercase strings. ```clojure (json/write-str {:a 1 :b 2} :key-fn #(.toUpperCase %)) ``` -------------------------------- ### Custom Key Conversion with Namespace Source: https://github.com/clojure/data.json/blob/master/README.md Use :key-fn with json/read-str to prepend a namespace to string keys, converting them into fully qualified keywords. ```clojure (json/read-str "{\"a\":1,\"b\":2}" :key-fn #(keyword "com.example" %)) ``` -------------------------------- ### Handle Dates and Times with data.json Source: https://context7.com/clojure/data.json/llms.txt Utilize built-in support for java.time.Instant, java.util.Date, and java.sql.Date. Custom formatting can be applied using the :date-formatter option. ```clojure (ns example (:require [clojure.data.json :as json]) (:import [java.time Instant ZoneId] [java.time.format DateTimeFormatter])) ;; Write java.time.Instant (default ISO-8601 format) (json/write-str {:created (Instant/parse "2024-01-15T10:30:00Z")}) ;;=> "{\"created\":\"2024-01-15T10:30:00Z\"}" ``` ```clojure ;; Write java.util.Date (json/write-str {:timestamp (java.util.Date. 1705315800000)}) ;;=> "{\"timestamp\":\"2024-01-15T10:30:00Z\"}" ``` ```clojure ;; Use custom date formatter (let [formatter (.withZone (DateTimeFormatter/ofPattern "yyyy-MM-dd HH:mm:ss") (ZoneId/of "UTC"))] (json/write-str {:date (Instant/parse "2024-01-15T10:30:00Z")} :date-formatter formatter)) ;;=> "{\"date\":\"2024-01-15 10:30:00\"}" ``` ```clojure ;; Custom SQL date converter (defn sql-date-to-instant [^java.sql.Date d] (.toInstant (.atStartOfDay (.toLocalDate d) (ZoneId/of "America/New_York")))) (json/write-str {:date (java.sql.Date/valueOf "2024-01-15")} :sql-date-converter sql-date-to-instant) ;;=> "{\"date\":\"2024-01-15T05:00:00Z\"}" ``` -------------------------------- ### Maven Dependency Source: https://github.com/clojure/data.json/blob/master/README.md Add this to your pom.xml file to include the data.json library. ```xml org.clojure data.json 2.5.2 ``` -------------------------------- ### Clojure CLI/deps.edn Dependency Source: https://github.com/clojure/data.json/blob/master/README.md Add this to your deps.edn file to include the data.json library. ```clojure org.clojure/data.json {:mvn/version "2.5.2"} ``` -------------------------------- ### Leiningen Dependency Source: https://github.com/clojure/data.json/blob/master/README.md Add this to your project.clj file to include the data.json library. ```clojure [org.clojure/data.json "2.5.2"] ``` -------------------------------- ### Basic JSON Parsing and Generation Source: https://github.com/clojure/data.json/blob/master/README.md Use json/write-str to convert Clojure data to JSON strings and json/read-str to parse JSON strings back into Clojure data. ```clojure (ns example (:require [clojure.data.json :as json])) ``` ```clojure (json/write-str {:a 1 :b 2}) ``` ```clojure (json/read-str "{\"a\":1,\"b\":2}") ``` -------------------------------- ### Pretty-Print JSON Source: https://context7.com/clojure/data.json/llms.txt Pretty-prints Clojure data as JSON to *out*, offering more readable output than write-str with :indent. Supports capturing output as a string and controlling Unicode escaping. ```clojure (ns example (:require [clojure.data.json :as json])) ;; Pretty-print to *out* (json/pprint {:users [{:name "Alice" :age 30} {:name "Bob" :age 25}] :metadata {:version "1.0"}}) ;; Output: ;; {"users": [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}], ;; "metadata": {"version": "1.0"}} ;; Capture pretty-printed output as string (with-out-str (json/pprint {:deeply {:nested {:structure {:value 42}}}})) ;;=> "{\"deeply\": {\"nested\": {\"structure\": {\"value\": 42}}}}\n" ;; Pretty-print with non-escaped Unicode (with-out-str (json/pprint {:greeting "Hello \u4e16\u754c"} :escape-unicode false)) ;;=> "{\"greeting\": \"Hello \u4e16\u754c\"}\n" ``` -------------------------------- ### Write JSON to Writer Source: https://context7.com/clojure/data.json/llms.txt Writes JSON-formatted output to a java.io.Writer, suitable for streaming or file output. Supports indentation and writing to standard output. ```clojure (ns example (:require [clojure.data.json :as json]) (:import [java.io StringWriter FileWriter])) ;; Write to a StringWriter (let [sw (StringWriter.)] (json/write {:name "Alice" :scores [95 87]} sw) (str sw)) ;;=> "{\"name\":\"Alice\",\"scores\":[95,87]}" ;; Write with indentation (let [sw (StringWriter.)] (json/write {:name "Alice"} sw :indent true) (str sw)) ;;=> "{\n \"name\": \"Alice\"\n}" ;; Write to a file (with-open [w (FileWriter. "/tmp/output.json")] (json/write {:data [1 2 3]} w :indent true)) ;; Creates file with formatted JSON content ;; Write to *out* (standard output) (json/write {:message "Hello"} *out*) ;; Prints: {"message":"Hello"} ``` -------------------------------- ### Transform Values with :key-fn and :value-fn Source: https://context7.com/clojure/data.json/llms.txt Apply transformations to keys and values during JSON reading and writing. The :value-fn can be used to modify specific data types or redact sensitive information. ```clojure (ns example (:require [clojure.data.json :as json])) ;; Omit specific keys during reading (defn skip-internal-keys [k v] (if (.startsWith (name k) "_") skip-internal-keys ; Return the function itself to omit v)) (json/read-str "{\"name\":\"Alice\",\"_internal\":\"secret\",\"age\":30}" :key-fn keyword :value-fn skip-internal-keys) ;;=> {:name "Alice", :age 30} ``` ```clojure ;; Transform specific value types during writing (defn transform-for-json [k v] (cond ;; Convert sets to sorted vectors (set? v) (vec (sort v)) ;; Convert keywords to uppercase strings (keyword? v) (.toUpperCase (name v)) ;; Convert NaN/Infinity to strings (and (number? v) (Double/isNaN (double v))) "NaN" (and (number? v) (Double/isInfinite (double v))) "Infinity" :else v)) (json/write-str {:tags #{:beta :alpha :gamma} :status :active} :value-fn transform-for-json) ;;=> "{\"tags\":[\"alpha\",\"beta\",\"gamma\"],\"status\":\"ACTIVE\"}" ``` ```clojure ;; Redact sensitive fields (defn redact-sensitive [k v] (if (#{:password :secret :api-key :ssn} k) "[REDACTED]" v)) (json/write-str {:username "alice" :password "secret123" :api-key "sk-abc123"} :value-fn redact-sensitive) ;;=> "{\"username\":\"alice\",\"password\":\"[REDACTED]\",\"api-key\":\"[REDACTED]\"}" ``` -------------------------------- ### Writing JSON to a Stream Source: https://github.com/clojure/data.json/blob/master/README.md Use json/write to serialize Clojure data directly to a java.io.Writer. ```clojure (json/write writer data) ``` -------------------------------- ### Read JSON from Reader Source: https://context7.com/clojure/data.json/llms.txt Parses a single JSON value from a java.io.Reader. For repeated reads, use PushbackReader. Options like :key-fn can be provided. ```clojure (ns example (:require [clojure.data.json :as json]) (:import [java.io StringReader PushbackReader])) ;; Read from a StringReader (json/read (StringReader. "{\"key\":\"value\"}")) ;;=> {"key" "value"} ;; Read with options (json/read (StringReader. "{\"name\":\"Alice\"}") :key-fn keyword) ;;=> {:name "Alice"} ;; Read multiple JSON objects from a single stream using PushbackReader (let [input "{\"first\":1}{\"second\":2}{\"third\":3}" pbr (PushbackReader. (StringReader. input) 64)] [(json/read pbr) (json/read pbr) (json/read pbr)]) ;;=> [{"first" 1} {"second" 2} {"third" 3}] ;; Handle EOF when reading from stream (let [pbr (PushbackReader. (StringReader. "42") 64)] (println "First read:" (json/read pbr)) (println "Second read:" (json/read pbr :eof-error? false :eof-value :done))) ;; First read: 42 ;; Second read: :done ``` -------------------------------- ### Handle Extra Data During JSON Parsing Source: https://context7.com/clojure/data.json/llms.txt Functions to detect and manage extra data after a valid JSON value. By default, extra data is ignored. Options like :extra-data-fn allow throwing exceptions or capturing remaining data. ```clojure (ns example (:require [clojure.data.json :as json])) ;; By default, extra data is ignored (json/read-str "[1,2,3] extra garbage") ;;=> [1 2 3] ;; Throw exception on extra data using on-extra-throw (try (json/read-str "[1,2,3],extra" :extra-data-fn json/on-extra-throw) (catch clojure.lang.ExceptionInfo e (println "Error:" (.getMessage e)) (println "Parsed value:" (:val (ex-data e))))) ;; Error: Found extra data after json object ;; Parsed value: [1 2 3] ;; Get the remaining data using on-extra-throw-remaining (try (json/read-str "{\"valid\":true}[extra,stuff]" :extra-data-fn json/on-extra-throw-remaining) (catch clojure.lang.ExceptionInfo e {:parsed (:val (ex-data e)) :remaining (:remaining (ex-data e))})) ;;=> {:parsed {"valid" true}, :remaining "[extra,stuff]"} ``` -------------------------------- ### Reading JSON from a Stream Source: https://github.com/clojure/data.json/blob/master/README.md Use json/read to parse JSON directly from a java.io.Reader. ```clojure (json/read reader) ``` -------------------------------- ### Extra Data Detection Functions Source: https://context7.com/clojure/data.json/llms.txt Helper functions for strict JSON parsing that detect and handle extra data after the first JSON value. ```APIDOC ## Extra Data Detection Functions ### Description Helper functions for strict JSON parsing that detect and handle extra data after the first JSON value. ### Method `on-extra-throw`, `on-extra-throw-remaining` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```clojure (require '[clojure.data.json :as json]) ;; By default, extra data is ignored (json/read-str "[1,2,3] extra garbage") ;;=> [1 2 3] ;; Throw exception on extra data using on-extra-throw (try (json/read-str "[1,2,3],extra" :extra-data-fn json/on-extra-throw) (catch clojure.lang.ExceptionInfo e (println "Error:" (.getMessage e)) (println "Parsed value:" (:val (ex-data e))))) ;; Error: Found extra data after json object ;; Parsed value: [1 2 3] ;; Get the remaining data using on-extra-throw-remaining (try (json/read-str "{\"valid\":true}[extra,stuff]" :extra-data-fn json/on-extra-throw-remaining) (catch clojure.lang.ExceptionInfo e {:parsed (:val (ex-data e)) :remaining (:remaining (ex-data e))})) ;;=> {:parsed {"valid" true}, :remaining "[extra,stuff]"} ``` ### Response #### Success Response (200) - **Parsed JSON value** (any) - The parsed JSON data. - **Remaining data** (string) - The portion of the input string that was not parsed as JSON (when using `on-extra-throw-remaining`). #### Response Example ```json { "parsed": {"valid": true}, "remaining": "[extra,stuff]" } ``` ``` -------------------------------- ### Pretty-Printing JSON Source: https://context7.com/clojure/data.json/llms.txt Function for pretty-printing Clojure data structures to standard output in a human-readable JSON format. ```APIDOC ## pprint - Pretty-Print JSON ### Description Pretty-prints JSON representation of Clojure data to *out* using the Clojure pretty-printer. Produces more readable output than write-str with :indent. ### Method `pprint` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```clojure (require '[clojure.data.json :as json]) ;; Pretty-print to *out* (json/pprint {:users [{:name "Alice" :age 30} {:name "Bob" :age 25}] :metadata {:version "1.0"}}) ;; Output: ;; {"users": [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}], ;; "metadata": {"version": "1.0"}} ;; Capture pretty-printed output as string (with-out-str (json/pprint {:deeply {:nested {:structure {:value 42}}}})) ;;=> "{\"deeply\": {\"nested\": {\"structure\": {\"value\": 42}}}}\n" ;; Pretty-print with non-escaped Unicode (with-out-str (json/pprint {:greeting "Hello \u4e16\u754c"} :escape-unicode false)) ;;=> "{\"greeting\": \"Hello \u4e16\u754c\"}\n" ``` ### Response #### Success Response (200) None (prints directly to *out*). #### Response Example None ``` -------------------------------- ### Parse JSON String to Clojure Data with read-str Source: https://context7.com/clojure/data.json/llms.txt Use `read-str` to parse a JSON string into a Clojure data structure. Options include customizing key and value transformations, decimal parsing, and EOF handling. ```clojure (ns example (:require [clojure.data.json :as json])) ;; Basic JSON parsing (json/read-str "{\"name\":\"Alice\",\"age\":30}") ;;=> {"name" "Alice", "age" 30} ;; Parse with keyword keys (json/read-str "{\"name\":\"Alice\",\"age\":30}" :key-fn keyword) ;;=> {:name "Alice", :age 30} ;; Parse arrays (json/read-str "[1, 2, 3, \"four\", true, null]") ;;=> [1 2 3 "four" true nil] ;; Parse nested structures with keyword keys (json/read-str "{\"user\":{\"profile\":{\"name\":\"Bob\"}}}" :key-fn keyword) ;;=> {:user {:profile {:name "Bob"}}} ;; Use BigDecimal for precise decimal handling (json/read-str "3.14159265358979323846" :bigdec true) ;;=> 3.14159265358979323846M ;; Handle empty input gracefully (json/read-str "" :eof-error? false :eof-value :no-data) ;;=> :no-data ;; Transform values during parsing (e.g., parse date strings) (json/read-str "{\"date\":\"2024-01-15\",\"count\":42}" :key-fn keyword :value-fn (fn [k v] (if (= k :date) (java.sql.Date/valueOf v) v))) ;;=> {:date #inst "2024-01-15", :count 42} ``` -------------------------------- ### Convert Clojure Data to JSON String with write-str Source: https://context7.com/clojure/data.json/llms.txt Use `write-str` to convert Clojure data structures into JSON strings. Options include controlling Unicode escaping, transforming keys and values, and pretty-printing. ```clojure (ns example (:require [clojure.data.json :as json])) ;; Basic JSON generation (json/write-str {:name "Alice" :age 30}) ;;=> "{\"name\":\"Alice\",\"age\":30}" ;; Write arrays (json/write-str [1 2 3 "four" true nil]) ;;=> "[1,2,3,\"four\",true,null]" ;; Write nested structures (json/write-str {:users [{:name "Alice"} {:name "Bob"}]}) ;;=> "{\"users\":[{\"name\":\"Alice\"},{\"name\":\"Bob\"}]}" ;; Pretty-print with indentation (json/write-str {:name "Alice" :scores [95 87 92]} :indent true) ;;=> "{\n \"name\": \"Alice\",\n \"scores\": [\n 95,\n 87,\n 92\n ]\n}" ;; Control Unicode escaping (json/write-str "Hello \u4e16\u754c" :escape-unicode false) ;;=> "\"Hello \u4e16\u754c\"" (json/write-str "Hello \u4e16\u754c" :escape-unicode true) ;;=> "\"Hello \\u4e16\\u754c\"" ;; Transform keys to uppercase (json/write-str {:name "Alice"} :key-fn #(.toUpperCase %)) ;;=> "{\"NAME\":\"Alice\"}" ;; Filter out nil values using value-fn (json/write-str {:a 1 :b nil :c 3} :value-fn (fn remove-nils [k v] (if (nil? v) remove-nils v))) ;;=> "{\"a\":1,\"c\":3}" ;; Write UUIDs (automatically converted to strings) (json/write-str {:id (java.util.UUID/fromString "550e8400-e29b-41d4-a716-446655440000")}) ;;=> "{\"id\":\"550e8400-e29b-41d4-a716-446655440000\"}" ;; Write dates (converted to ISO-8601 format) (json/write-str {:timestamp (java.time.Instant/parse "2024-01-15T10:30:00Z")}) ;;=> "{\"timestamp\":\"2024-01-15T10:30:00Z\"}" ``` -------------------------------- ### write-str - Convert Clojure Data to JSON String Source: https://context7.com/clojure/data.json/llms.txt Converts Clojure data structures to JSON-formatted strings. Supports options for Unicode escaping, key transformation, value transformation, indentation, and custom type handling. ```APIDOC ## write-str ### Description Converts Clojure data structures to JSON-formatted strings. Supports options for Unicode escaping, key transformation, value transformation, indentation, and custom type handling. ### Method N/A (Function Call) ### Endpoint N/A (Function Call) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```clojure (require '[clojure.data.json :as json]) ;; Basic JSON generation (json/write-str {:name "Alice" :age 30}) ;;=> "{\"name\":\"Alice\",\"age\":30}" ;; Write arrays (json/write-str [1 2 3 "four" true nil]) ;;=> "[1,2,3,\"four\",true,null]" ;; Write nested structures (json/write-str {:users [{:name "Alice"} {:name "Bob"}]}) ;;=> "{\"users\":[{\"name\":\"Alice\"},{\"name\":\"Bob\"}]}" ;; Pretty-print with indentation (json/write-str {:name "Alice" :scores [95 87 92]} :indent true) ;;=> "{\n \"name\": \"Alice\",\n \"scores\": [\n 95,\n 87,\n 92\n ]\n}" ;; Control Unicode escaping (json/write-str "Hello \u4e16\u754c" :escape-unicode false) ;;=> "\"Hello \u4e16\u754c\"" (json/write-str "Hello \u4e16\u754c" :escape-unicode true) ;;=> "\"Hello \\u4e16\\u754c\"" ;; Transform keys to uppercase (json/write-str {:name "Alice"} :key-fn #(.toUpperCase %)) ;;=> "{\"NAME\":\"Alice\"}" ;; Filter out nil values using value-fn (json/write-str {:a 1 :b nil :c 3} :value-fn (fn remove-nils [k v] (if (nil? v) remove-nils v))) ;;=> "{\"a\":1,\"c\":3}" ;; Write UUIDs (automatically converted to strings) (json/write-str {:id (java.util.UUID/fromString "550e8400-e29b-41d4-a716-446655440000")}) ;;=> "{\"id\":\"550e8400-e29b-41d4-a716-446655440000\"}" ;; Write dates (converted to ISO-8601 format) (json/write-str {:timestamp (java.time.Instant/parse "2024-01-15T10:30:00Z")}) ;;=> "{\"timestamp\":\"2024-01-15T10:30:00Z\"}" ``` ### Response #### Success Response (200) - **JSON String** (string) - The JSON-formatted string representation of the Clojure data. #### Response Example ```json { "example": "{\"name\": \"Alice\", \"age\": 30}" } ``` ``` -------------------------------- ### Handle Custom Types with default-write-fn Source: https://context7.com/clojure/data.json/llms.txt Define a custom function to serialize types not natively supported by data.json. This function is invoked when an unknown type is encountered during serialization. ```clojure (ns example (:require [clojure.data.json :as json])) ;; By default, unknown types throw an exception (try (json/write-str {:url (java.net.URI. "https://example.com")}) (catch Exception e (.getMessage e))) ;;=> "Don't know how to write JSON of class java.net.URI" ``` ```clojure ;; Define a custom write function for unknown types (defn custom-write-fn [value out options] ;; Convert unknown types to their string representation (.append out \") (.append out (str value)) (.append out \")) ;; Use custom handler for URI and other types (json/write-str {:url (java.net.URI. "https://example.com") :file (java.io.File. "/path/to/file")} :default-write-fn custom-write-fn) ;;=> "{\"url\":\"https://example.com\",\"file\":\"/path/to/file\"}" ``` ```clojure ;; More sophisticated custom handler with type checking (defn smart-write-fn [value out options] (cond (instance? java.net.URI value) (do (.append out \") (.append out (.toString ^java.net.URI value)) (.append out \")) (instance? java.util.regex.Pattern value) (do (.append out \") (.append out (.pattern ^java.util.regex.Pattern value)) (.append out \")) :else (throw (Exception. (str "Cannot serialize: " (class value)))))) (json/write-str {:pattern #"^\\d+$"} :default-write-fn smart-write-fn) ;;=> "{\"pattern\":\"^\\\\d+$\"}" ``` -------------------------------- ### Custom Value Conversion on Write Source: https://github.com/clojure/data.json/blob/master/README.md Define a :value-fn to transform values before JSON serialization. The function receives the key and value. Note: :value-fn only applies to map values. ```clojure (defn my-value-writer [key value] (if (= key :date) (str (java.sql.Date. (.getTime value))) value)) ``` ```clojure (json/write-str {:number 42, :date (java.util.Date. 112 5 2)} :value-fn my-value-writer :key-fn name) ``` -------------------------------- ### JSON Writing Functions Source: https://context7.com/clojure/data.json/llms.txt Functions for serializing Clojure data structures into JSON format and writing them to a Writer. ```APIDOC ## write - Write JSON to Writer ### Description Writes JSON-formatted output directly to a java.io.Writer. Useful for streaming large data sets or writing to files. ### Method `write` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```clojure (require '[clojure.data.json :as json]) (require '[java.io.StringWriter :as StringWriter]) ;; Write to a StringWriter (let [sw (StringWriter.)] (json/write {:name "Alice" :scores [95 87]} sw) (str sw)) ;;=> "{\"name\":\"Alice\",\"scores\":[95,87]}" ;; Write with indentation (let [sw (StringWriter.)] (json/write {:name "Alice"} sw :indent true) (str sw)) ;;=> "{\n \"name\": \"Alice\"\n}" ;; Write to a file (with-open [w (FileWriter. "/tmp/output.json")] (json/write {:data [1 2 3]} w :indent true)) ;; Creates file with formatted JSON content ;; Write to *out* (standard output) (json/write {:message "Hello"} *out*) ;; Prints: {"message":"Hello"} ``` ### Response #### Success Response (200) None (writes directly to the provided Writer). #### Response Example None ``` -------------------------------- ### JSON Reading Functions Source: https://context7.com/clojure/data.json/llms.txt Functions for parsing JSON data from various input sources. ```APIDOC ## read - Parse JSON from Reader ### Description Reads a single JSON value from a java.io.Reader. For repeated reads from the same source, use a PushbackReader with a buffer size of at least 64 characters. ### Method `read` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```clojure (require '[clojure.data.json :as json]) (require '[java.io.StringReader :as StringReader]) ;; Read from a StringReader (json/read (StringReader. "{\"key\":\"value\"}")) ;;=> {"key" "value"} ;; Read with options (json/read (StringReader. "{\"name\":\"Alice\"}") :key-fn keyword) ;;=> {:name "Alice"} ;; Read multiple JSON objects from a single stream using PushbackReader (let [input "{\"first\":1}{\"second\":2}{\"third\":3}" pbr (PushbackReader. (StringReader. input) 64)] [(json/read pbr) (json/read pbr) (json/read pbr)]) ;;=> [{"first" 1} {"second" 2} {"third" 3}] ;; Handle EOF when reading from stream (let [pbr (PushbackReader. (StringReader. "42") 64)] (println "First read:" (json/read pbr)) (println "Second read:" (json/read pbr :eof-error? false :eof-value :done))) ;; First read: 42 ;; Second read: :done ``` ### Response #### Success Response (200) - **Parsed JSON value** (any) - The parsed JSON data as a Clojure data structure. #### Response Example ```json {"key": "value"} ``` ``` -------------------------------- ### read-str - Parse JSON String to Clojure Data Source: https://context7.com/clojure/data.json/llms.txt Reads one JSON value from an input string and converts it to a Clojure data structure. Supports options for customizing key transformation, value transformation, decimal parsing behavior, and EOF handling. ```APIDOC ## read-str ### Description Reads one JSON value from an input string and converts it to a Clojure data structure. Supports options for customizing key transformation, value transformation, decimal parsing behavior, and EOF handling. ### Method N/A (Function Call) ### Endpoint N/A (Function Call) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```clojure (require '[clojure.data.json :as json]) ;; Basic JSON parsing (json/read-str "{\"name\":\"Alice\",\"age\":30}") ;;=> {"name" "Alice", "age" 30} ;; Parse with keyword keys (json/read-str "{\"name\":\"Alice\",\"age\":30}" :key-fn keyword) ;;=> {:name "Alice", :age 30} ;; Parse arrays (json/read-str "[1, 2, 3, \"four\", true, null]") ;;=> [1 2 3 "four" true nil] ;; Parse nested structures with keyword keys (json/read-str "{\"user\":{\"profile\":{\"name\":\"Bob\"}}}" :key-fn keyword) ;;=> {:user {:profile {:name "Bob"}}} ;; Use BigDecimal for precise decimal handling (json/read-str "3.14159265358979323846" :bigdec true) ;;=> 3.14159265358979323846M ;; Handle empty input gracefully (json/read-str "" :eof-error? false :eof-value :no-data) ;;=> :no-data ;; Transform values during parsing (e.g., parse date strings) (json/read-str "{\"date\":\"2024-01-15\",\"count\":42}" :key-fn keyword :value-fn (fn [k v] (if (= k :date) (java.sql.Date/valueOf v) v))) ;;=> {:date #inst "2024-01-15", :count 42} ``` ### Response #### Success Response (200) - **Clojure Data Structure** (any) - The parsed Clojure data structure. #### Response Example ```json { "example": "{\"name\": \"Alice\", \"age\": 30}" } ``` ``` -------------------------------- ### Custom Value Conversion on Read Source: https://github.com/clojure/data.json/blob/master/README.md Define a :value-fn to transform values during JSON parsing. The function receives the key and value, allowing conditional transformations. Note: :value-fn only applies to map values. ```clojure (defn my-value-reader [key value] (if (= key :date) (java.sql.Date/valueOf value) value)) ``` ```clojure (json/read-str "{\"number\":42,\"date\":\"2012-06-02\"}" :value-fn my-value-reader :key-fn keyword) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.