Search code examples
javajson-simple

Adding JSON Array to already existing JSON file


I have already existing JSON file similiar to this:

[{
    "x": []
}]

and I want to put prepared JSON Array as a value for "x" key. How to do it using JSON Simple library?


Solution

  • Quick solution:

        JSONObject jsonObject = (JSONObject) jsonArray.get(0);
        jsonObject.put("x", jsonArrayWithValueForXKey);
        jsonArray.clear();
        jsonArray.add(jsonObject);