Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8127533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:33:50+00:00 2026-06-06T07:33:50+00:00

Converting json to oher type should be easy. From the Play! documentation : var

  • 0

Converting json to oher type should be easy. From the Play! documentation:

var str = "{\"next_cursor\":0,\"ids\":[123123,345345],\"previous_cursor\":0}"
var fol = Json.parse(str)
var fin = Json.fromJson[List[String]].fromJson(fol)

Should work without problem. It compiles fine, but failed with this error:

[RuntimeException: List expected]

Instead, this works:

var str = "{\"next_cursor\":0,\"ids\":[123123,345345],\"previous_cursor\":0}"
var fol = Json.parse(str)
var fin = (fol \ "ids") match {
    case ids: JsArray => ids.value.map(_.toString)
    case _ => JsArray()
}

Why? Am I understanding something wrong with the API? I’m trying this in PlayFramework 2.0.1.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:33:52+00:00Added an answer on June 6, 2026 at 7:33 am

    You can’t parse this as a List[String] directly, as it is a list of numbers, not strings. Your match example works because you map the ids to a string afterwards. Using your example, you’d write it more like:

    val str = "{\"next_cursor\":0,\"ids\":[123123,345345],\"previous_cursor\":0}"
    val fol = Json.parse(str)
    val fin = Json.fromJson[List[Int]](fol \ "ids")
    

    To make the syntax slightly easier to read, I’d make use of JsValue.as[T], which is the equivalent of Json.fromJson[T]:

    val fin = (fol \ "ids").as[List[Int]]
    

    And if you need the ids to be converted to strings:

    val fin = (fol \ "ids").as[List[Int]].map(_.toString)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am converting a c# LINQ example: var query = from m in typeof(string).GetMethods()
I am converting from JSON to object and from object to array. It does
I am getting the following result from converting xml to JSON, using more than
I need a easy to use library whit examples for converting NSObjects to JSON
I'm currently puling data from an external XML file and converting it to JSON
Spring MVC + Jackson converting Java object to/from Json data. I want to validate
JSON.stringify is converting my json object to the following string {\2003\:{\1\:{\2\:[\test\],\3\:[\test2\]}}} When it should
Possible Duplicate: Converting XML to JSON using Python? I'm doing some work on App
For converting a integer into an enum (out of a json file), I declared
I was converting NSString to NSData in order to parse by JSON, but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.