Use JacksonJSON library or GSON which may be easiest one.
http://www.studytrails.com/java/json/java-google-json-parse-json-to-java-tree/
See this answer how to create JSON object from Map<String,String>
object. You just need to split an input string accordingly.
https://stackoverflow.com/a/18444414/185565
Map<String,String> myMap = new HashMap<String,String>();
//..populate mymap..
Gson gson = new Gson();
String json = gson.toJson(myMap);
Here is a copypaste example from the gson documentation in case the previous link stopped working. This one reads a json string to json object so is not a direct answer to your question but may come handy.
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.commons.io.IOUtils;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class ParseTreeExample6 {
public static void main(String[] args) throws MalformedURLException, IOException {
String url = "http://freemusicarchive.org/api/get/albums.json?api_key=60BLHNQCAOUFPIBZ&limit=5";
String json = IOUtils.toString(new URL(url));
JsonParser parser = new JsonParser();
JsonElement element = parser.parse(json);
if (element.isJsonObject()) {
JsonObject albums = element.getAsJsonObject();
System.out.println(albums.get("title").getAsString());
JsonArray datasets = albums.getAsJsonArray("dataset");
for (int i = 0; i < datasets.size(); i++) {
JsonObject dataset = datasets.get(i).getAsJsonObject();
System.out.println(dataset.get("album_title").getAsString());
}
}
}
}