java - Removing JSON elements with jackson -
i've particular json node corresponds import org.codehaus.jackson.jsonnode, , not import org.codehaus.jackson.map.jsonnode.
[ { "givenname": "jim", "formattedname": "jimjackson", "familyname": null, "middlename": "none", "honorificprefix": "mr", "honorificsuffix": "none" }, { "givenname": "john", "formattedname": "johnlasher", "familyname": null, "middlename": "none", "honorificprefix": "mr", "honorificsuffix": "none" }, { "givenname": "carlos", "formattedname": "carlosaddner", "familyname": null, "middlename": "none", "honorifiprefix": "mr", "honorificsuffix": "none" }, { "givenname": "lisa", "formattedname": "lisaray", "familyname": null, "middlename": "none", "honorificprefix": "mrs", "honorificsuffix": "none" }, { "givenname": "bradshaw", "formattedname": "bradshawlion", "familyname": null, "middlename": "none", "honorificprefix": "mr", "honorificsuffix": "none" }, { "givenname": "phill", "formattedname": "phillkane", "familyname": null, "middlename": "none", "honorificprefix": "mr", "honorificsuffix": "none" }, { "givenname": "gabriel", "formattedname": "gabrielmoosa", "familyname": null, "middlename": "none", "honorificprefix": "mr", "honorificsuffix": "none" } ]
i want remove "familyname" , "middlename" json nodes of above array. there way achieve this?
i haven't tested this, think want:
import org.codehaus.jackson.node.objectnode; // ... (jsonnode personnode : rootnode) { if (personnode instanceof objectnode) { objectnode object = (objectnode) personnode; object.remove("familyname"); object.remove("middlename"); } }
you more efficiently using jackon's raw parsing api, code lot messier.
Comments
Post a Comment