我需要构建一个JSON字符串,如下所示:

[
  { 'id': 1, 'name': 'John'},
  { 'id': 2, 'name': 'Dani'}
]

val jArray = JsArray();
jArray += (("id", "1"), ("name", "John"))
jArray += (("id", "2"), ("name", "Dani"))
println(jArray.dump)

I need to be able to add rows to the jArray, something like jArray += ...

与此最接近的库/解决方案是什么?

推荐答案

不幸的是,编写JSON库是Scala社区编写待办事项列表应用程序的版本.

有很多种 Select .我没有按特定顺序列出它们,并附上注释:

  1. parsing.json.JSON - Warning this library is available only up to Scala version 2.9.x (removed in newer versions)
  2. spray-json-从喷雾项目中提取
  3. Jerkson±-Warning一个不错的库(建立在Java Jackson之上),但现在放弃了它.如果你要使用这个,可能要遵循滚烫项目的例子,使用backchat.io fork
  4. sjson - By Debasish Ghosh
  5. lift-json-可与电梯项目分开使用
  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 - A handy, safe and efficient JSON library, uses jsoniter-scala under hood.
  10. sonofjson-JSON库,旨在实现超级简单的API
  11. Jawn - JSON library by Erik Osheim aiming for Jackson-or-faster speed
  12. Rapture JSON±-一个JSON前端,可以使用2、4、5、6、7、11或Jackson作为后端
  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
  15. jackson-module-scala-Jackson的附加模块,支持Scala特定的数据类型
  16. borer - Efficient CBOR and JSON (de)serialization in Scala

? = has not fixed security vulnerabilities, § = has Scalaz integration, ± = supports interop with Jackson JsonNode

In Snowplow we use json4s with the Jackson back-end; we've had good experiences with Argonaut too.

Json相关问答推荐

将数据从嵌套的SON数组提取到更简单的数组中

解析SQL中的嵌套JSON

Jolt-在数组列表中插入新的字段

从Postgres表中的JSON中提取值

(Kotlin)com.google.gson.internal.LinkedTreeMap无法转换为com.example.phonetest2.model.HallData

为什么 Django Rest API 序列化器没有正确序列化多对多字段

在 PowerShell 中通过 aws cli 创建 cloudwatch alert 时出现字符串解析错误

基于JQ中另一个对象的值 Select 对象

如何在 Apps 脚本中循环遍历 JSON 响应

将来自 Golang 的 JSON API 调用响应输出到 nextjs 前端

Powershell 7.2:ConvertFrom-Json - 日期处理

如何使用 gson 将数据保存在 json 文件中?

Python Flask-Restful POST 不采用 JSON 参数

如何使用 Swift 从 NSURLSession 获取 cookie?

反序列化大型 json 对象的 JsonMaxLength 异常

Django - 异常处理最佳实践和发送自定义错误消息

在 HTML 数据属性上添加 JSON 是不是很糟糕?

MySQL Select JSON 字段属性具有值的位置

PHP json_encode json_decode UTF-8

Java HashMap 与 JSONObject