0

我正在使用Cheshire为如下数据结构生成一些 JSON:

(require '[cheshire.core :refer [generate-string])
(generate-string {:id 123, :foo "something", :bar nil})

这会产生这样的 JSON:

{"id": 123, "foo": "something", "bar": null}

我想要的是让 JSON 省略没有值的键;例如

{"id": 123, "foo": "something"}

柴郡能做到吗?我当然可以在调用之前预先过滤地图generate-string,但是由于 Cheshire 无论如何都必须遍历我的数据结构,我认为指示 Cheshire 进行过滤会更好。

4

1 回答 1

1

不,null 是有效的 JSON 值,因此您应该nil自己过滤值。

有关更多信息,请参阅此问题

您可以向 Cheshire 团队提出此功能。

于 2014-05-14T16:12:33.410 回答