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

  • SEARCH
  • Home
  • 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 9147885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:06:40+00:00 2026-06-17T11:06:40+00:00

I need to be able to process large JSON files, instantiating objects from deserializable

  • 0

I need to be able to process large JSON files, instantiating objects from deserializable sub-strings as we are iterating-over/streaming-in the file.

For example:

Let’s say I can only deserialize into instances of the following:

case class Data(val a: Int, val b: Int, val c: Int)

and the expected JSON format is:

{   "foo": [ {"a": 0, "b": 0, "c": 0 }, {"a": 0, "b": 0, "c": 1 } ], 
    "bar": [ {"a": 1, "b": 0, "c": 0 }, {"a": 1, "b": 0, "c": 1 } ], 
     .... MANY ITEMS .... , 
    "qux": [ {"a": 0, "b": 0, "c": 0 }  }

What I would like to do is:

import com.codahale.jerkson.Json
val dataSeq : Seq[Data] = Json.advanceToValue("foo").stream[Data](fileStream)
// NOTE: this will not compile since I pulled the "advanceToValue" out of thin air.

As a final note, I would prefer to find a solution that involves Jerkson or any other libraries that comes with the Play framework, but if another Scala library handles this scenario with greater ease and decent performance: I’m not opposed to trying another library. If there is a clean way of manually seeking through the file and then using a Json library to continue parsing from there: I’m fine with that.

What I do not want to do is ingest the entire file without streaming or using an iterator, as keeping the entire file in memory at a time would be prohibitively expensive.

  • 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-17T11:06:42+00:00Added an answer on June 17, 2026 at 11:06 am

    Here is the current way I am solving the problem:

    import collection.immutable.PagedSeq
    import util.parsing.input.PagedSeqReader
    import com.codahale.jerkson.Json
    import collection.mutable
    
    private def fileContent = new PagedSeqReader(PagedSeq.fromFile("/home/me/data.json"))
    private val clearAndStop = ']'
    
    private def takeUntil(readerInitial: PagedSeqReader, text: String) : Taken = {
      val str = new StringBuilder()
      var readerFinal = readerInitial
    
      while(!readerFinal.atEnd && !str.endsWith(text)) {
        str += readerFinal.first
        readerFinal = readerFinal.rest
      }
    
      if (!str.endsWith(text) || str.contains(clearAndStop))
        Taken(readerFinal, None)
      else
        Taken(readerFinal, Some(str.toString))
    }
    
    private def takeUntil(readerInitial: PagedSeqReader, chars: Char*) : Taken = {
      var taken = Taken(readerInitial, None)
      chars.foreach(ch => taken = takeUntil(taken.reader, ch.toString))
    
      taken
    }
    
    def getJsonData() : Seq[Data] = {
      var data = mutable.ListBuffer[Data]()
      var taken = takeUntil(fileContent, "\"foo\"")
      taken = takeUntil(taken.reader, ':', '[')
    
      var doneFirst = false
      while(taken.text != None) {
        if (!doneFirst)
          doneFirst = true
        else
          taken = takeUntil(taken.reader, ',')
    
        taken = takeUntil(taken.reader, '}')
        if (taken.text != None) {
          print(taken.text.get)
          places += Json.parse[Data](taken.text.get)
        }
      }
    
      data
    }
    
    case class Taken(reader: PagedSeqReader, text: Option[String])
    case class Data(val a: Int, val b: Int, val c: Int)
    

    Granted, This code doesn’t exactly handle malformed JSON very cleanly and to use for multiple top-level keys “foo”, “bar” and “qux”, will require looking ahead (or matching from a list of possible top-level keys), but in general: I believe this does the job. It’s not quite as functional as I’d like and isn’t super robust but PagedSeqReader definitely keeps this from getting too messy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to be able to send a file to another website from server-side
Scenario I have a very heavy number-crunching process that pools large datasets from 3
I'm in the process of porting a large C++ application from Linux (gcc) to
I need to take a large array of doubles, and process it in chunks
In my application I need to load large files (can be about ~ 250
I am making a web app that will process large files (1gb+). While the
Users of the website need to able to store images in their area ,
Need to be able to pull Magento products into an external template. Need to
I need to be able to access a list throughout my Rails project. For
I need to be able to search through multiple 2D arrays and search the

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.