File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Code generates invalid Json Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Code generates invalid Json" Watch "Code generates invalid Json" New topic
Author

Code generates invalid Json

Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 499

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.>


Are you better than me? Then please show me my mistakes..
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18879
    
    8

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

Joined: Oct 07, 2010
Posts: 499

Thanks for the reply. I can post the complete code if you can give some hand
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18879
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Code generates invalid Json