• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Code generates invalid Json

 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to read a Json file (which contains a `JsonArray`) in `Amazon S3` using `Gson`, add extra 2 fields to every `JsonObject`, add the `JsonObject`s into a `JsonArray` and write the `JsonArray` back to a file.

Below is how the .json file I am reading looks like.



Below is my code, trying to do everything explained above




As you can see, I need to generate a .json file after 100 `JsonObjects` are collected. But my code generate invalid Json. It simply generate the following Json for the above code.




As you can see, it is invalid and it does not have 100 `JsonObject`s. What have I done wrong here? Please help. It is invalid because it does not close the JsonObject and JsonArray properly with brackets.

Is there no one in SO to help this problem?

PS: Please note that I made this question in here as well, but I did not get any valuable answer.>
 
Paul Clapham
Sheriff
Pie
Posts: 20729
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see any code which writes JSON, so it's kind of hard to comment on that code. But if your problem is that the end of the expected data is missing, chances are that the code writing the data failed to close the file (or output stream or whatever).
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I can post the complete code if you can give some hand
 
Paul Clapham
Sheriff
Pie
Posts: 20729
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand what kind of help you need to post the appropriate code.

Actually... what you need to do is to explain the existing code. What's a "JsonArray"? What is this mysterious "s3" variable which seems to be in charge of everything? If you're going to use classes which aren't part of the standard Java API then the least you can do is to explain them. Or post a link to their documentation. Or something; don't just assume that somebody is going to know all about them.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic