Details
-
Type:
Defect
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Completed
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Environment:clojure.data.json 0.2.0
-
Patch:Code and Test
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}"
Attachments
Activity
Andy Fingerhut
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Attachment | djson-7-dont-write-unnecessary-commas-v1.txt [ 11811 ] |
Andy Fingerhut
made changes -
| Patch | Code and Test [ 10002 ] |
Stuart Sierra
made changes -
| Resolution | Completed [ 1 ] | |
| Assignee | Stuart Sierra [ stuart.sierra ] | |
| Status | Open [ 1 ] | Resolved [ 5 ] |
djson-7-dont-write-unnecessary-commas-v1.txt dated Jan 21 2013 modifies write-object so that it only writes out a comma if :value-fn does not cause the key/value pair to be omitted.