在Scala中使用哪个JSON库? [英] What JSON library to use in Scala?
问题描述
我需要构建一个JSON字符串,如下所示:
I need to build a JSON string, something like this:
[
{ 'id': 1, 'name': 'John'},
{ 'id': 2, 'name': 'Dani'}
]
val jArray = JsArray();
jArray += (("id", "1"), ("name", "John"))
jArray += (("id", "2"), ("name", "Dani"))
println(jArray.dump)
我需要能够将行添加到jArray
,类似于jArray += ...
I need to be able to add rows to the jArray
, something like jArray += ...
与此最接近的库/解决方案是什么?
What is the closest library/solution to this?
推荐答案
不幸的是,编写JSON库是Scala社区编写待办事项列表应用程序的版本.
Unfortunately writing a JSON library is the Scala community's version of coding a todo list app.
有很多选择.我没有特别的顺序列出它们,并带有注释:
There are quite a variety of alternatives. I list them in no particular order, with notes:
- 解析. json.JSON -警告:此库仅在Scala 2.9.x版(在较新版本中已删除)之前可用.
- spray-json -从Spray项目中提取
- Jerkson ±-警告一个不错的库(建立在Java Jackson),但现在已经放弃了.如果要使用此功能,则可以遵循Scalding项目的示例,并使用 backchat.io fork
- sjson -由Debasish Ghosh
- lift-json -可以与Lift项目分开使用
- json4s §±-从lift-json中提取的内容,它正在尝试创建标准JSON其他JSON库可以使用的AST.包括由杰克逊支持的实施方案
- Argonaut §-来自Scalaz背后人员的面向FP的面向Scala的JSON库
- play-json ±-现在可以独立使用,请参见有关详细信息的答案
- 第戎-警告已被放弃.动态类型的Scala JSON库
- sonofjson -旨在提供超简单API的JSON库
- Jawn -Erik Osheim的JSON库,旨在实现杰克逊或更快的速度
- 捕获JSON ±-可使用2、4、5的JSON前端,6、7、11或杰克逊作为后端
- 圈子-Argonaut的叉子建立在 jsoniter-scala -用于在编译时生成超快速JSON编解码器的Scala宏
- parsing.json.JSON - Warning this library is available only up to Scala version 2.9.x (removed in newer versions)
- spray-json - Extracted from the Spray project
- Jerkson ± - Warning a nice library (built on top of Java Jackson) but now abandonware. If you are going to use this, probably follow the Scalding project's example and use the backchat.io fork
- sjson - By Debasish Ghosh
- lift-json - Can be used separately from the Lift project
- json4s § ± - An extraction from lift-json, which is attempting to create a standard JSON AST which other JSON libraries can use. Includes a Jackson-backed implementation
- Argonaut § - A FP-oriented JSON library for Scala, from the people behind Scalaz
- play-json ± - Now available standalone, see this answer for details
- dijon - Warning abandoned. A dynamically typed Scala JSON library
- sonofjson - JSON library aiming for a super-simple API
- Jawn - JSON library by Erik Osheim aiming for Jackson-or-faster speed
- Rapture JSON ± - a JSON front-end which can use 2, 4, 5, 6, 7, 11 or Jackson as back-ends
- circe - fork of Argonaut built on top of cats instead of scalaz
- jsoniter-scala - Scala macros for compile-time generation of ultra-fast JSON codecs
§=具有Scalaz集成,±=支持与Jackson JsonNode
§ = has Scalaz integration, ± = supports interop with Jackson JsonNode
在 Snowplow 中,我们将json4s与Jackson后端一起使用;我们在Argonaut上也有很好的经验.
In Snowplow we use json4s with the Jackson back-end; we've had good experiences with Argonaut too.
这篇关于在Scala中使用哪个JSON库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!