![]() Some of the complexity is incidental: e.g. ![]() None of these examples using Scala libraries are as simple, or easy, as the Python, Ruby, or Javascript examples, or the uJson example shown above. _.read.map(x => JsString(x.value.reverse)) Val jsonTransformer = (_ \ "name").json.update( Val data2 = ("name").withFocus(_.mapString(_.reverse)).top.get Scala AlternativesĬompare the above uPickle examples to the complexity of manipulating JSON in the various Scala libraries: Argonaut import scalaz._, Scalaz._į -> (if (f = "name") o(f).get.withString(_.reverse) else o(f).get)Ĭirce import io.circe._, io.circe.parser._ uJson makes it both simple and easy to work with JSON, so you can spend less time thinking about JSON and more time on things which are actually important to you: your business logic, application, and product. With uJson, you have a JSON library that does what you want to do, rather than forcing you to learn how to library wants to do things. Js.Obj("myFieldA" -> 2, "myFieldB" -> "k")Īnd trivial structures are trivial to construct: val nums = Js.Arr(1, 2, 3)ĭue to uJson's mutable data model, you probably already know how to modify any of the structures above, including modifying values nested in arrays and dictionaries: nested(0)("myFieldA") = 123 Nested structures are constructed similarly: val nested = Js.Arr( Here's an example constructing a JSON dictionary ( Js.Obj) from the Ammonite codebase: import ujson._ obj for casting to other common JSON types.Ĭonstructing JSON values using uJson is also simple, using the Js.* constructors. This is simply a property of working in a statically-typed language: it's effectively a cast to say "this JSON value is a String" to allow you to work with it as a String. using ("name") instead of for dictionary lookup), the only additional syntax here is the. With uJson, manipulating JSON should be just as simple and familiar regardless of what your programming background is: val data = ujson.read(input)Īpart from the minor syntactic differences from Python/Ruby/Javascript (e.g. In most languages, such as Python, Ruby or Javascript, it is trivial: Python import jsonĭata = data.split("").reverse().join("")Įach of the above examples is trivial even a beginner learning Python, Ruby or Javascript would have no problem understanding what each one is doing! A trivial code snippet is a fitting way of implementing a trivial task. ![]() to reverse the string, would seem like a trivial operation that should have a trivial solution. However, none of them achieve the heights of intuitiveness that someone coming from Python, Ruby or Javascript might expect working with JSON data types. There are a lot of existing JSON libraries in Scala: Circe, Argonaut, Play-Json, and many others.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |