• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is it possible to parse Json without knowing the structure in advance?

 
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We can parse json using any json parser like Boon or other by creating the POJOs according to the structure.For this we need to know the structure in advance so that we create POJOs for the attributes.Is it possible to parse Json without knowing the structure in advance?

thanks
 
Author
Posts: 141
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Monica,
sure, you can always parse into a Map/List.

If however you are just talking about "ignoring" certain fields in your data structure, most libraries allow you to use  a POJO which does not 1:1 reflect the JSON, and simply ignore any unknown fields.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Groovy parses without knowing any of the structure.  So definitely possible.

It's cool in Groovy because then you can use dot notation to query the parsed structure.
reply
    Bookmark Topic Watch Topic
  • New Topic