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 8164741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:23:01+00:00 2026-06-06T19:23:01+00:00

i have a json file with many elements like these: { code : hfuiew89,

  • 0

i have a json file with many elements like these:

{ 
"code" : "hfuiew89", 
"type" : "location", 
"coordinates" : [ { "lat" : 40.9861, "lon" : 29.1046, "index" : 1 }, 
          { "lat" : 40.9976, "lon" : 29.1153, "index" : 2 }, 
          { "lat" : 40.9809, "lon" : 29.2194, "index" : 3 }] 
}
{ 
"code" : "klsdsjh", 
"type" : "location", 
"relatedTags" : [ "kolmha" ], 
"coordinates" : [ { "lat" : 40.9808, "lon" : 29.1605, "index" : 1 }, 
              { "lat" : 40.9965, "lon" : 29.1672, "index" : 2 }] 
}

i want to read that file with gson but all examples i found are only for one element. therefore after reading the first one, throws ‘Expected EOF’ exception. how can i overcome this?

  • 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-06T19:23:02+00:00Added an answer on June 6, 2026 at 7:23 pm

    Greg is right, this is incorrect JSON, and you should try to generate valid JSON, that is prepend “[” at the beginning, append “]” at the end, and separate each element with a comma (“,”), so that it is a JSON array of JSON object.

    However, if you cannot change the format you have, consider it “a string containing a concatenation of well formed JSON fragments”. Approaching it that way, break the big string into smaller, valid json strings, and parse them one by one.

    To break the big string into single fragments you can simply count the brackets. With a “pre-parser” that copies stuff into a buffer (a StringBuilder?), increments a counter each time it encounters a “{“, decreases it each time it enouters a “}”, and if the counter is at zero pass the buffer string to gson for parsing, clear the buffer and go on to the end of the file.

    You can even use that pre-parser to convert it to valid json, simply appending a “,” when the counter reaches zero, and the passing everything to gson for a single parsing, but that could mean loading everything into ram, and I don’t know how big your file is.

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

Sidebar

Related Questions

I have parse json file which contain more than hundred location name, there latitude
I have a large JSON file that contains A LOT of similar code. It's
I have the following json code file named: sections.json { section1: { priority: 1,
I am writing a custom textfile-data parser (JSON-like) and I have lost many hours
I have a json file/stream, i like to be able to make select SQL
I have a JSON file which looks like the following: {"posts":[{"Latitude":"53.38246685","lontitude":"-6.41501535"}, {"Latitude":"53.4062787","lontitude":"-6.3767205"}]} and I
I have a file with many hundreds of lines of json encoded tweets pulled
I have a json file of data and the only item for time i
I have a JSON file that has more name value pairs than I care
I have a huge JSON file to parse in my Android app. I suppose

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.