We're updating the issue view to help you get more done. 

Write-str outputs invalid JSON when key/value pairs are removed

Description

When key/value pairs are removed by the function defined for :value-fn, commas are still output and this results in invalid JSON. To remove the errant commas, I've had to wrap write-str in (write-str (read-str ())).

Here is a simple example from the REPL:

main=> (defn remove-nils [k v]
#_=> (if (nil? v)
#_=> remove-nils
#_=> v))

main=> (def test
#_=> {:a nil,
#_=> :b nil,
#_=> :c 1,
#_=> :d nil,
#_=> :e 2
#_=> :f nil})

main=> (json/write-str test :value-fn remove-nils)
;=>"{,\"c\":1,,,\"e\":2,}"

main=> (json/write-str (json/read-str (json/write-str test :value-fn remove-nils)))
;=>"{\"c\":1,\"e\":2}"

Environment

clojure.data.json 0.2.0

Status

Assignee

Stuart Sierra

Reporter

import

Labels

None

Approval

None

Patch

Code and Test

Priority

Minor