1

I'm writing a server that need to parse JSON strings uploaded by clients. Currently I'm using Play JSON lib. For example:

import play.api.libs.json._

def parseJSON(jsonString: String) = {
    val jsv = Json.parse(jsonString)
    jsv
}

Considering a client uploaded a JOSN string of {"key1": 1}. After the server received the entire string, just simple invoke the parseJSONmethod, everything will be done.

However, if a client uploaded TWO JSON strings, {"key2": 2} and {"key3": 3}, and due to the bad network, these two JSON strings reach the server at the same time. The server will get a long string of {"key2": 2}{"key3": 3} (The server can not know it contains two JSON strings before parsing). if I invoke the parseJSON method and pass the entire string, only the first JSON value {"key2": 2} will be returned. The second one {"key3": 3} will be ignored.

So, how can I parse the second JSON string? Is there a way to know how many Chars are used when parsing the first JSON string?

Hwaipy Li
  • 53
  • 4
  • If you're ingesting a stream of JSON properly its probably not going to be a trivial endeavor [Scanning a HUGE JSON file for deserializable data in Scala](https://stackoverflow.com/questions/14365694/scanning-a-huge-json-file-for-deserializable-data-in-scala) – cantuket Feb 16 '19 at 03:11

1 Answers1

0
val jsonString2 = """{
    "key1": 1,
    "key2": 2
    }
    {
    "key3": 3,
 """

I think this is not valid JSON value, please make your question cleaner as possible so we can help :)

Rex
  • 558
  • 2
  • 9