Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse a json string to a case class in scaja.js and vice versa

Tags:

json

scala.js

A JSON string:

{
    "name": "Mike",
    "age": 111
}

A case class:

case class User(name:String, age:Int)

If I use scala, there are many libraries can let me convert the JSON to the case class and vice versa, but they can't be used in scala.js.

How to do this work in scala.js?

like image 335
Freewind Avatar asked Feb 18 '15 14:02

Freewind


2 Answers

Use one of the pickling libraries that work with Scala.js. The following two produce well-behaved and predictable JSON:

  • uPickle
  • Prickle
like image 56
sjrd Avatar answered Oct 06 '22 22:10

sjrd


Circe has more than 1000 stars: https://github.com/circe/circe

like image 1
Waldemar Wosiński Avatar answered Oct 06 '22 23:10

Waldemar Wosiński