<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged json</title>
<link>https://ask.clojure.org/index.php/tag/json</link>
<description></description>
<item>
<title>An undocumented breaking change in data.json</title>
<link>https://ask.clojure.org/index.php/14728/an-undocumented-breaking-change-in-data-json</link>
<description>&lt;p&gt;between the versions &lt;code&gt;1.1.0&lt;/code&gt; and &lt;code&gt;2.0.0&lt;/code&gt;, data.json introduced a breaking change: The &lt;code&gt;JSONWriter#-write&lt;/code&gt; signature changed from &lt;code&gt;[object out]&lt;/code&gt; to &lt;code&gt;[object out options]&lt;/code&gt;&lt;br&gt;
On this commit:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/data.json/commit/8f070ba94dc7c469f303259ce5f5bfa0b53d50bd&quot;&gt;https://github.com/clojure/data.json/commit/8f070ba94dc7c469f303259ce5f5bfa0b53d50bd&lt;/a&gt;&lt;br&gt;
In release notes &lt;code&gt;Release 2.0.0 on 2021-Mar-19 &lt;/code&gt;, there is no mention to &lt;code&gt;JSONWriter&lt;/code&gt; or &lt;code&gt;-write&lt;/code&gt; protocol changes.&lt;/p&gt;
&lt;p&gt;I know it's a very old problem, but I think this documentation could be present.&lt;/p&gt;
</description>
<category>data.json</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14728/an-undocumented-breaking-change-in-data-json</guid>
<pubDate>Thu, 23 Oct 2025 17:18:23 +0000</pubDate>
</item>
<item>
<title>Separate text from JSON to process JSON</title>
<link>https://ask.clojure.org/index.php/14200/separate-text-from-json-to-process-json</link>
<description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I'm starting with Clojure, better yet, re-starting after trying it several years ago.&lt;br&gt;
There are some new tools like Babashka that I'm trying to use for this.&lt;/p&gt;
&lt;p&gt;The challenge is to do the following:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Start ansible virtual environment &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run an external process with 'ansible-inventory' against one host&lt;br&gt;
at a time, or all hosts, let's see...&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The interesting part of the output of 'ansible-inventory' goes to&lt;br&gt;
stderr, so read it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It consists of lines of text and then some JSON.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Parse the JSON contents.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;It will be more elaborate than this, but it's enough for the case.&lt;/p&gt;
&lt;p&gt;Let's forget about 1.&lt;/p&gt;
&lt;p&gt;Instead of 2., just do a simple 'cat a.txt' file built with some text and some JSON like&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;line1
line 2
{
  'field': 'value'
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What I've been able to build was this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/usr/bin/env bb

(require '[babashka.process :refer [shell]])
(require '[cheshire.core :as json])
(require '[clojure.string :as str])

(-&amp;gt; (shell {:out :string} &quot;cat&quot; &quot;a.txt&quot;)
    :out json/parse-string)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What I'do in an imperative language, that I use to use would be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Read line by line.   In Clojure (str/split-lines)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Discard any line until a line consisiting only of a '{' is found.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;From there, accumulate all lines in a string until a '}' is found.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Parse the JSON from that string.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;How can I approach this in Clojure?&lt;/p&gt;
</description>
<category>IO</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14200/separate-text-from-json-to-process-json</guid>
<pubDate>Fri, 18 Oct 2024 14:10:03 +0000</pubDate>
</item>
<item>
<title>Accidental breaking change in data.json 2.5.0: previously, read succeeded, now it isn't</title>
<link>https://ask.clojure.org/index.php/14134/accidental-breaking-change-data-json-previously-succeeded</link>
<description>&lt;p&gt;Here is a snippet of code that fails on data.json 2.5.0:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;clj -Sdeps '{:deps {org.clojure/data.json {:mvn/version &quot;2.5.0&quot;}}}' -M -e '((requiring-resolve (quote clojure.data.json/read)) (clojure.lang.LineNumberingPushbackReader. (java.io.StringReader. &quot;[\n  {\n    \&quot;name\&quot;: \&quot;position\&quot;,\n    \&quot;type\&quot;: \&quot;float32\&quot;,\n    \&quot;count\&quot;: 3,\n    \&quot;data\&quot;: [0,0,0]\n  },\n  {\n    \&quot;name\&quot;: \&quot;normal\&quot;,\n    \&quot;type\&quot;: \&quot;float32\&quot;,\n    \&quot;count\&quot;: 3,\n    \&quot;data\&quot;: [0,0,0]\n  },\n  {\n    \&quot;name\&quot;: \&quot;texcoord0\&quot;,\n    \&quot;type\&quot;: \&quot;float32\&quot;,\n    \&quot;count\&quot;: 2,\n    \&quot;data\&quot;: [0,0]\n  }\n]&quot;)))'

Execution error (IOException) at java.io.PushbackReader/unread (PushbackReader.java:166).
Pushback buffer overflow
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The same code succeeds on 2.4.0:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;clj -Sdeps '{:deps {org.clojure/data.json {:mvn/version &quot;2.4.0&quot;}}}' -M -e '((requiring-resolve (quote clojure.data.json/read)) (clojure.lang.LineNumberingPushbackReader. (java.io.StringReader. &quot;[\n  {\n    \&quot;name\&quot;: \&quot;position\&quot;,\n    \&quot;type\&quot;: \&quot;float32\&quot;,\n    \&quot;count\&quot;: 3,\n    \&quot;data\&quot;: [0,0,0]\n  },\n  {\n    \&quot;name\&quot;: \&quot;normal\&quot;,\n    \&quot;type\&quot;: \&quot;float32\&quot;,\n    \&quot;count\&quot;: 3,\n    \&quot;data\&quot;: [0,0,0]\n  },\n  {\n    \&quot;name\&quot;: \&quot;texcoord0\&quot;,\n    \&quot;type\&quot;: \&quot;float32\&quot;,\n    \&quot;count\&quot;: 2,\n    \&quot;data\&quot;: [0,0]\n  }\n]&quot;)))'
[{&quot;name&quot; &quot;position&quot;, &quot;type&quot; &quot;float32&quot;, &quot;count&quot; 3, &quot;data&quot; [0 0 0]} {&quot;name&quot; &quot;normal&quot;, &quot;type&quot; &quot;float32&quot;, &quot;count&quot; 3, &quot;data&quot; [0 0 0]} {&quot;name&quot; &quot;texcoord0&quot;, &quot;type&quot; &quot;float32&quot;, &quot;count&quot; 2, &quot;data&quot; [0 0]}]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The gist of the problem: previously, Clojure's line numbering pushback reader could be used as an input to &lt;code&gt;read&lt;/code&gt;. Now it can't: it throws an exception.&lt;/p&gt;
&lt;p&gt;For reference, this is a json repro (a valid json!):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[
  {
    &quot;name&quot;: &quot;position&quot;,
    &quot;type&quot;: &quot;float32&quot;,
    &quot;count&quot;: 3,
    &quot;data&quot;: [0,0,0]
  },
  {
    &quot;name&quot;: &quot;normal&quot;,
    &quot;type&quot;: &quot;float32&quot;,
    &quot;count&quot;: 3,
    &quot;data&quot;: [0,0,0]
  },
  {
    &quot;name&quot;: &quot;texcoord0&quot;,
    &quot;type&quot;: &quot;float32&quot;,
    &quot;count&quot;: 2,
    &quot;data&quot;: [0,0]
  }
]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And, the formatted code: that uses the json:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(clojure.data.json/read 
  (clojure.lang.LineNumberingPushbackReader.
    (java.io.StringReader. &quot;...&quot;)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It seems the problem is introduced in &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/DJSON-50&quot;&gt;https://clojure.atlassian.net/browse/DJSON-50&lt;/a&gt;&lt;/p&gt;
</description>
<category>data.json</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14134/accidental-breaking-change-data-json-previously-succeeded</guid>
<pubDate>Wed, 25 Sep 2024 15:46:20 +0000</pubDate>
</item>
<item>
<title>Should clojure.data.json protect against duplicate keys when writing a combination of keyword and string keys?</title>
<link>https://ask.clojure.org/index.php/13589/clojure-protect-against-duplicate-writing-combination-keyword</link>
<description>&lt;p&gt;When running &lt;code&gt;(json/write-str {:a 1 &quot;a&quot; 2})&lt;/code&gt; it outputs &lt;code&gt;;; =&amp;gt; &quot;{\&quot;a\&quot;:1,\&quot;a\&quot;:2}&quot;&lt;/code&gt;. Should there be a validation to assert no duplicate keys exist? Or is it on the user to: 1. Not to mix keyword keys and string keys, and 2. Validate if there are no duplicate keys?&lt;/p&gt;
</description>
<category>data.json</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13589/clojure-protect-against-duplicate-writing-combination-keyword</guid>
<pubDate>Tue, 02 Jan 2024 22:16:45 +0000</pubDate>
</item>
<item>
<title>REST API response body is not a string?</title>
<link>https://ask.clojure.org/index.php/10217/rest-api-response-body-is-not-a-string</link>
<description>&lt;p&gt;It's been a while since I've written Clojure, so I am rusty.&lt;/p&gt;
&lt;p&gt;Basically, I'm trying to write code which does an HTTP GET on a REST API and converts that JSON array of objects into clojure data (list of Maps?). The JSON data looks like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[
    {
        &quot;id&quot;: 1,
        &quot;category&quot;: &quot;technical&quot;,
        &quot;asin&quot;: &quot;0131103628&quot;,
        &quot;title&quot;: &quot;C Programming Language, 2nd Edition&quot;,
        &quot;publication_date&quot;: &quot;1988-04-01T00:00:00Z&quot;,
        &quot;review&quot;: &quot;The C book.&quot;,
        &quot;created_at&quot;: &quot;2020-03-06T20:48:00Z&quot;
    },
    {
        &quot;id&quot;: 2,
        &quot;category&quot;: &quot;technical&quot;,
        &quot;asin&quot;: &quot;0387966080&quot;,
        &quot;title&quot;: &quot;The Science of Fractal Images&quot;,
        &quot;publication_date&quot;: &quot;1988-07-19T00:00:00Z&quot;,
        &quot;review&quot;: &quot;The book on fractal algorithms.  Sadly, no longer in print.  I had to search high and low for a used copied.&quot;,
        &quot;created_at&quot;: &quot;2020-03-06T20:48:00Z&quot;
    },
    // etc..
]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I'm using &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/http-kit/http-kit&quot;&gt;http-kit&lt;/a&gt; (I've also tried &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/dakrone/clj-http&quot;&gt;clj-http&lt;/a&gt;) to call the REST API and return the body. Later, I try converting the body to Clojure data. I've tried using both &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/data.json&quot;&gt;org.clojure/data.json&lt;/a&gt; and &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/dakrone/cheshire&quot;&gt;cheshire&lt;/a&gt;.  However, I don't belive the data is being converted correctly.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defn get-books-body
  []
  (:body @(client/get books-url api-options)))

(defn get-books
  []
  (parse-string get-books-body true))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When I try to display the type of the body, it shows up as an address instead of a string:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;clojure-json-test.core=&amp;gt; (type get-books-body)
clojure_json_test.core$get_books_body
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And I cannot look at the first record, after converting from JSON:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;clojure-json-test.core=&amp;gt; (first get-books)
Execution error (IllegalArgumentException) at clojure-json-test.core/eval3169 (form-      init15378865171954877190.clj:1).
Don't know how to create ISeq from: clojure_json_test.core$get_books
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Any idea what I am doing wrong?&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10217/rest-api-response-body-is-not-a-string</guid>
<pubDate>Sat, 20 Feb 2021 08:42:46 +0000</pubDate>
</item>
<item>
<title>json writer and namespaces</title>
<link>https://ask.clojure.org/index.php/9758/json-writer-and-namespaces</link>
<description>&lt;p&gt;Hello &lt;/p&gt;
&lt;p&gt;I'm new to Clojure and didn't find answer so please sorry if this is not issue at all. &lt;/p&gt;
&lt;p&gt;lets say we have data: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{:space1/value 123 :space2/value 456}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and use &lt;code&gt;clojure.data.json&lt;/code&gt; as serialiser: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(clojure.data.json/write-str {:space1/value 123 :space2/value 456})
=&amp;gt; &quot;{\&quot;value\&quot;:123,\&quot;value\&quot;:456}&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you see result is not what one can expect.&lt;br&gt;
Obvious solution would be to provide own &lt;code&gt;key-fn&lt;/code&gt; and forget about it. But I spend a lot of time catching bug caused by default implementation and like to save time of other &lt;/p&gt;
</description>
<category>data.json</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9758/json-writer-and-namespaces</guid>
<pubDate>Thu, 05 Nov 2020 11:50:53 +0000</pubDate>
</item>
<item>
<title>Reading a JSON stream over HTTP, indefinitely?</title>
<link>https://ask.clojure.org/index.php/9128/reading-a-json-stream-over-http-indefinitely</link>
<description>&lt;p&gt;I am trying to read a &lt;code&gt;json&lt;/code&gt; HTTP stream and use the &lt;code&gt;json&lt;/code&gt; elements, indefinitely.&lt;/p&gt;
&lt;p&gt;I came up with this code below, but it does close the stream and only returns 30 results - how do I &lt;em&gt;indefinitely&lt;/em&gt; use the HTTP stream?&lt;/p&gt;
&lt;p&gt;Thanks for your help!&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns core
  (:require [clj-http.client :as http]
            [cheshire.core :as json]
            [clojure.java.io :as io]
            [clojure.core.async :as async]))

(def gh-url &quot;https://api.github.com/events&quot;)
(def chan (async/chan 100))

(async/go
  (loop [r (async/&amp;lt;! chan)]
    (when (not-empty r) (println (:type r)))
    (recur (async/&amp;lt;! chan))))

(defn read-gh-stream [url]
  (with-open [stream (-&amp;gt; url (http/get {:as :stream}) :body)]
    (let [lines (-&amp;gt; stream io/reader (json/parse-stream true))]
      (doseq [l lines]
        (async/go
          (async/&amp;gt;! chan l))))))
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>IO</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9128/reading-a-json-stream-over-http-indefinitely</guid>
<pubDate>Sat, 29 Feb 2020 07:59:50 +0000</pubDate>
</item>
<item>
<title>Any good tutorials on clojure-walk ?</title>
<link>https://ask.clojure.org/index.php/9119/any-good-tutorials-on-clojure-walk</link>
<description>&lt;p&gt;I want to develop a tool that ingests json into native clojure data-structure and then provides a jq /json-pointer like select/map/filter api or capabilities. I believe clojure-walk might solve this. &lt;/p&gt;
</description>
<category>Meta</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9119/any-good-tutorials-on-clojure-walk</guid>
<pubDate>Sun, 23 Feb 2020 21:06:03 +0000</pubDate>
</item>
<item>
<title>Best way to write a unix(y) tool with Clojure ?</title>
<link>https://ask.clojure.org/index.php/9084/best-way-to-write-a-unix-y-tool-with-clojure</link>
<description>&lt;p&gt;I was looking for a way to use Clojure data/json to convert back and forth from json but I cannot find any easy way to take unescaped json from stdin and output lisp like expression tree to stdout or vice-versa.&lt;/p&gt;
&lt;p&gt;P.S: 'Hello World' is the 1st program people teach, I think 'Echo back' should be the second one. &lt;br&gt;
Or something like &lt;br&gt;
&amp;gt; This is Houston. Say again, please.&lt;br&gt;
&amp;gt; Houston, we've had a problem.&lt;/p&gt;
</description>
<category>Libs</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9084/best-way-to-write-a-unix-y-tool-with-clojure</guid>
<pubDate>Mon, 10 Feb 2020 00:08:35 +0000</pubDate>
</item>
<item>
<title>Is the standard JSON parser broken ?</title>
<link>https://ask.clojure.org/index.php/8860/is-the-standard-json-parser-broken</link>
<description>&lt;p&gt;It seems that the &quot;standard&quot; json parser is happily parsing invalid json as shown below&lt;br&gt;
&lt;code&gt;user=&amp;gt; (require '[clojure.data.json :as j])
nil
user=&amp;gt; (j/read-str &quot;{\&quot;a\&quot;: 123,,}&quot;)
{&quot;a&quot; 123}
user=&amp;gt; (j/read-str &quot;{\&quot;a\&quot;: 123,\&quot;b\&quot;,}&quot;)
{&quot;a&quot; 123}&lt;/code&gt;&lt;br&gt;
I know other libraries exist (eg jsonista, cheshire) but it doesn't look good that what seems to be the &quot;standard&quot; json parser (as per the link on &lt;a rel=&quot;nofollow&quot; href=&quot;http://json.org/&quot;&gt;http://json.org/&lt;/a&gt; and the fact that it lives inside the main clojure github org) is broken.&lt;/p&gt;
&lt;p&gt;(Logged as &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/DJSON-29&quot;&gt;https://clojure.atlassian.net/browse/DJSON-29&lt;/a&gt;)&lt;/p&gt;
</description>
<category>data.json</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/8860/is-the-standard-json-parser-broken</guid>
<pubDate>Mon, 18 Nov 2019 16:41:29 +0000</pubDate>
</item>
<item>
<title>Why does Transit not allow serialization of clojure(script) functions ? What is the inherent difficulty there ?</title>
<link>https://ask.clojure.org/index.php/8254/transit-serialization-clojure-functions-inherent-difficulty</link>
<description>&lt;p&gt;I am trying to serialize my datascript database to JSON for storage on a filesystem. &lt;br&gt;
Some of the data inside my database includes functions. For reasons that are not interesting, I need to store them in the database for now with other session info for the application. But I get an exception that transit &quot;cannot write Function&quot;&lt;/p&gt;
&lt;p&gt;I looked at the code and it simply tries to handle data structures only - maps, vectors, etc. But there is no handler for functions. So I KNOW WHY I get the error, but the gist of my question is why it was not implemented to be able to serialize functions as well ? &lt;/p&gt;
&lt;p&gt; Is it just too novel an thought ? &lt;/p&gt;
&lt;p&gt; thanks&lt;/p&gt;
</description>
<category>ClojureScript</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/8254/transit-serialization-clojure-functions-inherent-difficulty</guid>
<pubDate>Mon, 29 Jul 2019 23:10:55 +0000</pubDate>
</item>
</channel>
</rss>