Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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.</p> <p>There is however one problem in your JSON. The <code>/</code> in <code>banned/censored</code> 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. </p> <p>I can recommend using <a href="http://code.google.com/p/google-gson/" rel="noreferrer">Google Gson</a> for the converting between JSON and Java. Here's a kickoff example based on your JSON structure (with <code>banned/censored</code> renamed to <code>bannedOrCensored</code>):</p> <pre><code>class Data { private String type; private List&lt;Feature&gt; features; } class Feature { private String type; private Properties properties; private Geometry geometry; } class Properties { private String NAME; private String bannedOrCensored; private Integer Bombed; private Double LON; private Double LAT; } class Geometry { private String type; private Double[][][][] coordinates; } </code></pre> <p>You only need to add/generate getters and setters yourself. Then, you'll be able to convert between JSON and Java like follows:</p> <pre><code>Data data = new Gson().fromJson(jsonString, Data.class); </code></pre> <p>To convert between CSV and a Java object, just pick one of the many CSV parsers, like <a href="http://opencsv.sourceforge.net" rel="noreferrer">OpenCSV</a>. You can even homegrow your own with help of <code>BufferedReader</code>.</p> <p>Finally, after altering the Java object representing the JSON data, you can convert it back to JSON string with help of Gson as follows:</p> <pre><code>String json = new Gson().toJson(data); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload