在Scala中使用哪个JSON库? [英] What JSON library to use in Scala?

查看:514
本文介绍了在Scala中使用哪个JSON库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要构建一个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:

  1. 解析. json.JSON -警告:此库仅在Scala 2.9.x版(在较新版本中已删除)之前可用.
  2. spray-json -从Spray项目中提取
  3. Jerkson ±-警告一个不错的库(建立在Java Jackson),但现在已经放弃了.如果要使用此功能,则可以遵循Scalding项目的示例,并使用 backchat.io fork
  4. sjson -由Debasish Ghosh
  5. lift-json -可以与Lift项目分开使用
  6. json4s §±-从lift-json中提取的内容,它正在尝试创建标准JSON其他JSON库可以使用的AST.包括由杰克逊支持的实施方案
  7. Argonaut §-来自Scalaz背后人员的面向FP的面向Scala的JSON库
  8. play-json ±-现在可以独立使用,请参见有关详细信息的答案
  9. 第戎-警告已被放弃.动态类型的Scala JSON库
  10. sonofjson -旨在提供超简单API的JSON库
  11. Jawn -Erik Osheim的JSON库,旨在实现杰克逊或更快的速度
  12. 捕获JSON ±-可使用2、4、5的JSON前端,6、7、11或杰克逊作为后端
  13. 圈子-Argonaut的叉子建立在 jsoniter-scala -用于在编译时生成超快速J​​SON编解码器的Scala宏
  1. parsing.json.JSON - Warning this library is available only up to Scala version 2.9.x (removed in newer versions)
  2. spray-json - Extracted from the Spray project
  3. 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
  4. sjson - By Debasish Ghosh
  5. lift-json - Can be used separately from the Lift project
  6. 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
  7. Argonaut § - A FP-oriented JSON library for Scala, from the people behind Scalaz
  8. play-json ± - Now available standalone, see this answer for details
  9. dijon - Warning abandoned. A dynamically typed Scala JSON library
  10. sonofjson - JSON library aiming for a super-simple API
  11. Jawn - JSON library by Erik Osheim aiming for Jackson-or-faster speed
  12. Rapture JSON ± - a JSON front-end which can use 2, 4, 5, 6, 7, 11 or Jackson as back-ends
  13. circe - fork of Argonaut built on top of cats instead of scalaz
  14. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆