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

json, scala.js

Solution

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

- uPickle

- Prickle

Problem

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?

Original source