How do I create JSON objects programmatically in playframework 2.1 scala

http://www.playframework.com/documentation/2.1.x/ScalaJson

That document says the idiomatic style of json creation is:

import play.api.libs.json.Json
Json.obj( "key" -> "value )

However this fails to compile as String -> String is not String -> Json.JsValueWrapper

It appears that play provides the code needed for implicit conversions in play.api.libs.json.{DefaultReads, DefaultWrites}

How do I get these implicit conversions into scope?

Answers


You've misspelt your import statement; it should be import play.api.libs.json.Json (it's important to remember Scala is case-sensitive). Fixing that, the code works:

scala> :paste
// Entering paste mode (ctrl-D to finish)

import play.api.libs.json.Json
Json.obj("key" -> "value")

// Exiting paste mode, now interpreting.

import play.api.libs.json.Json
res0: play.api.libs.json.JsObject = {"key":"value"}

scala>

Need Your Help

Svn advice — splitting a program into two parts

svn tortoisesvn

I'd Like advice setting up a svn structure and strategy. Here's the deal.

How do I get certificate's key size

c# x509certificate2

I have an X.509 certificate and need to get the size of its key (in bits) - e.g., 1024 2048 etc. I have looked at X509Certificate2 and also the bouncycastle X509Certificate classes but can't see ho...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.