scala 自带json,在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)

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

What is the closest library/solution to this?

解决方案

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:

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

§ = 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值