Dead silence! Not often you experience that on Stackoverflow... I've added a small bounty to get things going!
I've built a json document containing information about the location of various countries. I have added some custom keys. This is the beginning of the json-file:
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": {
"NAME": "Antigua and Barbuda",
"banned/censored": "AG",
"Bombed": 29,
"LON": -61.783000, "LAT": 17.078000 },
"geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -61.686668,...
All the custom keys (like bombed, banned/censored etc.) have values, but they are just old (bogus if you want) values. The real values are kept in a .csv file extracted from a excel document.
I e.g. have this:
banned/censored bombed
Antigua and Barbuda 2 120
...
Now I want to match these values with the proper key in the json-file. Is there any programs out there that I can use? Another option would be a json library for java, which somehow supports what I want. I havent been able to find an easy solution for it yet. The document is pretty large ~ 10MB, if it makes any difference!
EDIT: I've used QGIS to manipulate the .shp file, so some kind of extension could be of use too.
Just convert both the JSON and the CSV to a fullworthy Java object. This way you can write any Java logic to your taste to alter the Java objects depending on the one or other. Finally convert the modified Java object representing the JSON data back to a JSON string.
There is however one problem in your JSON. The
/
inbanned/censored
is not a valid character for a JSON field name, so many of the existing JSON deserializers may choke on this. If you fix this, then you'll be able to use one of them.I can recommend using Google Gson for the converting between JSON and Java. Here's a kickoff example based on your JSON structure (with
banned/censored
renamed tobannedOrCensored
):You only need to add/generate getters and setters yourself. Then, you'll be able to convert between JSON and Java like follows:
To convert between CSV and a Java object, just pick one of the many CSV parsers, like OpenCSV. You can even homegrow your own with help of
BufferedReader
.Finally, after altering the Java object representing the JSON data, you can convert it back to JSON string with help of Gson as follows:
While BalusC's answer tells you how to do it in your current setup, I have a more radical suggestion: get rid of the JSON.
By idea JSON is not meant to store data - it is meant to be used as a "lightweight text-based open standard designed for human-readable data interchange". That is:
Data storages on the other hand have much more requirements than this. That's why databases exist. So move your storage to a database. If you don't want a full-featured database, use something like HSQLDB or JavaDB.