convert string to json node code example
Example 1: node string to json
const json = '{"result":true, "count":42}';
const obj = JSON.parse(json);
Example 2: jackson create object node from string
@Testpublic
void givenTheJsonNode_whenRetrievingDataFromId_thenCorrect() throws JsonParseException, IOException {
String jsonString = "{"k1":"v1","k2":"v2"}";
ObjectMapper mapper = new ObjectMapper();
JsonNode actualObj = mapper.readTree(jsonString);
JsonNode jsonNode1 = actualObj.get("k1");
assertThat(jsonNode1.textValue(), equalTo("v1"));
}
Example 3: jackson create object node from string
@Testpublic void givenTheJsonNode_whenRetrievingDataFromId_thenCorrect() throws JsonParseException, IOException { String jsonString = "{"k1":"v1","k2":"v2"}"; ObjectMapper mapper = new ObjectMapper(); JsonNode actualObj = mapper.readTree(jsonString);