Search code examples
javajsonhttprequest

How to convert String to JsonObject


I am using a httprequest to get Json from a web into a string.

It is probably quite simple, but I cannot seem to convert this string to a javax.json.JsonObject.

How can I do this?


Solution

  • JsonReader jsonReader = Json.createReader(new StringReader("{}"));
    JsonObject object = jsonReader.readObject();
    jsonReader.close();
    

    See docs and examples.