scala-jsonr


License

License

Categories

Categories

Scala Languages JSON Data
GroupId

GroupId

co.torri
ArtifactId

ArtifactId

scala-jsonr_2.9.1
Last Version

Last Version

0.5
Release Date

Release Date

Type

Type

jar
Description

Description

scala-jsonr
scala-jsonr
Project URL

Project URL

https://github.com/lucastorri/scala-jsonr/
Project Organization

Project Organization

co.torri

Download scala-jsonr_2.9.1

How to add to project

<!-- https://jarcasting.com/artifacts/co.torri/scala-jsonr_2.9.1/ -->
<dependency>
    <groupId>co.torri</groupId>
    <artifactId>scala-jsonr_2.9.1</artifactId>
    <version>0.5</version>
</dependency>
// https://jarcasting.com/artifacts/co.torri/scala-jsonr_2.9.1/
implementation 'co.torri:scala-jsonr_2.9.1:0.5'
// https://jarcasting.com/artifacts/co.torri/scala-jsonr_2.9.1/
implementation ("co.torri:scala-jsonr_2.9.1:0.5")
'co.torri:scala-jsonr_2.9.1:jar:0.5'
<dependency org="co.torri" name="scala-jsonr_2.9.1" rev="0.5">
  <artifact name="scala-jsonr_2.9.1" type="jar" />
</dependency>
@Grapes(
@Grab(group='co.torri', module='scala-jsonr_2.9.1', version='0.5')
)
libraryDependencies += "co.torri" % "scala-jsonr_2.9.1" % "0.5"
[co.torri/scala-jsonr_2.9.1 "0.5"]

Dependencies

compile (1)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.9.1

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.9.1 jar 1.6.1

Project Modules

There are no modules declared in this project.

what

jsonr is a very simple library to create JSON strings in Scala.

repo

Version are available on the Sonatype repository. To use with SBT, add the following line to your build.sbt:

libraryDependencies += "co.torri" %% "scala-jsonr" % "0.5"

using

jsonr can be used in two forms: json description or object serialization. Both forms are described on the following sections. For a full list on how to use it, please check the available unit tests.

In both cases it is necessary to import the lib on where it will be used, like:

import co.torri.jsonr._

json description

In this form JSON objects are described using the special method $. It receive a sequence of key/pairs, which are separated by an arrow symbol (->). All the basic types are supported. An example of this form of usage is:

var json = $(
  "key"   -> "value",
  "int"   -> 2,
  "array" -> List(1, 2, 3),
  "more"  -> List($("foo" -> "bar"))
)

println(json)
// {"key": "value", "int": 2, "array": [1, 2, 3], "more": [{"foo": "bar"}]}

object serialization

Any existent object can be automatically converted to JSON using the special method .toJson:

case class Address(city: String, country: String)
case class Person(name: String, val age: Int, address: Address)
val json = Person("Lucas", 25, Address("Porto Alegre", "BR")).toJson

println(json)
// {"name": "Lucas", "age": 25, "address": {"city": "Porto Alegre", "country": "BR"}}

The same apply for Maps:

val json = Map("one" -> 1, "two" -> 2).toJson

println(json)
// {"one": 1, "two": 2}

Versions

Version
0.5