Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Parsing a JSON file

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been looking for the solution to parsing a full 'json' file. I have been looking for the solution but I am beginning to feel like the file is not actually a json file.
My first question would be if it actually is a JSON file and my second would be how I would go about parsing the full file into an array which I can later output.
I have been searching online but every solution I find either doesn't work (to my knowledge) or only includes a simple example with only one set of data that is laid out in a simple way. I am looking to parse a certain json file if it would be possible found at "https://www.accountkiller.com/xml/json/", I am trying to read the json file as a way to learn how to read more advanced file types instead of a basic text document.
I would  greatly appreciate the help from anyone who would help me as I don't even have a starting point, thank you for your help in advance.

P.S. I have attempted to attach the json file but all possible formats appear to be blocked.
 
Marshal
Posts: 26914
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

declan disley wrote:P.S. I have attempted to attach the json file but all possible formats appear to be blocked.



But a JSON file is text, and it's very easy to paste text into your post. So if your mystery file isn't text then it isn't a JSON file. However if it is text and you just don't know whether it's JSON, then go ahead and post it here.

Also reading text is reading text. There's no special way to read any text format. You may (and likely will) have to do something special to parse and interpret that text after you read it, but that's a separate issue.
 
declan disley
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I forgot I could try that,
Anyway I have now attempted to insert the text itself but it contains information which the forum does not allow due to a website which is included in the file. I do not wish to cause alarm and I can assure anyone the website is perfectly legal and safe to use without any hesitation. It is a simple website which allows you to find your accounts on multiple online websites and remove them from one central location. They chose to include a link to a json file incase someone ever did one to create a library in such a fashion.
I am sorry for the inconvenience I may have caused but I simply can't insert the text, instead I have included a snippet from the file which may suffice for getting the general gist of what the file is doing.

{ "list": [ { "url": "http://000webhost.com", "name": "000webhost", "ease": "1", "instructions": "http://www.accountkiller.com\/en\/delete-000webhost-account" }, { "url": "http://123people.com", "name": "123people.com", "ease": "2", "instructions": "http://www.accountkiller.com\/en\/delete-123people-com-account" }, { "url": "http://123rf.com", "name": "123 Royalty Free", "ease": "2", "instructions": "http://www.accountkiller.com\/en\/delete-123rf-com-account" }, { "url": "http://123video.nl", "name": "123video", "ease": "3", "instructions": "http://www.accountkiller.com\/en\/delete-123video-account" }, { "url": "http://192.com", "name": "192.com", "ease": "3", "instructions": "http://www.accountkiller.com\/en\/delete-192-com-account" }, { "url": "http://www.1channel.ch", "name": "1channel", "ease": "1", "instructions": "http://www.accountkiller.com\/en\/delete-1channel-account" }, { "url": "http://www.1up.com", "name": "1UP", "ease": "2", "instructions": "http://www.accountkiller.com\/en\/delete-1up-account" }, { "url": "http://www.24kitchen.nl", "name": "24kitchen.nl", "ease": "1", "instructions": "http://www.accountkiller.com\/en\/delete-24kitchen-nl-account" }, { "url": "http://2shared.com", "name": "2Shared", "ease": "1", "instructions": "http://www.accountkiller.com\/en\/delete-2shared-account" }, { "url": "http://www.32red.com", "name": "32red", "ease": "1", "instructions": "http://www.accountkiller.com\/en\/delete-32red-account" }, { "url": "http://3docean.net", "name": "3docean", "ease": "3", "instructions": "http://www.accountkiller.com\/en\/delete-3docean-account" }, { "url": "http://411.com", "name": "411", "ease": "1", "instructions": "http://www.accountkiller.com\/en\/delete-411-account" }, { "url": "http://www.43places.com", "name": "43Places", "ease": "3", "instructions": "http://www.accountkiller.com\/en\/delete-43places-account" }, { "url": "http://www.43things.com", "name": "43things", "ease": "3", "instructions": "http://www.accountkiller.com\/en\/delete-43things-account" }], "updated": 1492297411 }

Again sorry for the poor convenience on my part.
 
Marshal
Posts: 3727
534
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

declan disley wrote:... I have attempted to attach the json file but all possible formats appear to be blocked.


It is a JSON formatted text file, but it is huge.  Here is a snippet:

Edit: Looks like we both had the same idea
 
Ron McLeod
Marshal
Posts: 3727
534
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at this thread.  The structure of the data is similar to yours.  The OP used Gson to deserialize the data into a collection of Java objects - it would probably be a good fit for what you are wanting to do.

Give it a try and post back here if you hit any road blocks along the way.
 
Saloon Keeper
Posts: 7181
166
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
json.org is another widely used Java JSON library.
 
Ranch Hand
Posts: 45
2
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

http://tutorials.jenkov.com/java-json/jackson-objectmapper.html Gices a good overview about the topic.

Regards,

uwe
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic