A slight variation on Richards answer but readTree can take a string so you can simplify it to:

ObjectMapper mapper = new ObjectMapper();
JsonNode actualObj = mapper.readTree("{\"k1\":\"v1\"}");
Answer from slashnick on Stack Overflow
🌐
Baeldung
baeldung.com › home › json › jackson › jackson – marshall string to jsonnode
Jackson - Marshall String to JsonNode | Baeldung
June 28, 2023 - @Test public void whenParsingJsonStringIntoJsonNode_thenCorrect() throws JsonParseException, IOException { String jsonString = "{\"k1\":\"v1\",\"k2\":\"v2\"}"; ObjectMapper mapper = new ObjectMapper(); JsonNode actualObj = mapper.readTree(jsonString); assertNotNull(actualObj); }
🌐
Medium
medium.com › @salvipriya97 › jsonnode-explained-with-examples-d0c05324f61d
JsonNode explained with examples. What is JsonNode in Java? | by Priya Salvi | Medium
July 2, 2024 - Query JSON Data: Extract specific information from JSON data using path-based queries. import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; public class Main { public static void main(String[] args) { String jsonString = "{\"name\":\"John\",\"age\":30,\"address\":{\"street\":\"123 Main St\",\"city\":\"Anytown\"}}"; ObjectMapper objectMapper = new ObjectMapper(); try { // Parse JSON string into a JsonNode JsonNode rootNode = objectMapper.readTree(jsonString); // Accessing fields String name = rootNode.path("name").asText(); int age = rootNode.path(
🌐
Attacomsian
attacomsian.com › blog › jackson-convert-json-string-to-json-node
Convert JSON string to JsonNode using Jackson
October 14, 2022 - To convert a JSON string to JsonNode, you can use the readTree() method from ObjectMapper.
🌐
GitHub
github.com › FasterXML › jackson-databind › issues › 3073
Get JsonNode from String but not only JsonString · Issue #3073 · FasterXML/jackson-databind
March 8, 2021 - I know that we can convert JsonString to JsonNode By ObjectMapper mapper = new ObjectMapper(); JsonNode actualObj = mapper.readTree(jsonString); But my value is not only JsonString but also String So I want to convert it correctly to spe...
Author: FasterXML
🌐
Jenkov
jenkov.com › tutorials › java-json › jackson-jsonnode.html
Jackson JsonNode
The Jackson JsonNode class contains a set of methods that can convert a field value to another data type. For instance, convert a String field value to a long, or the other way around.
🌐
GitHub
gist.github.com › ucheng › 3121142
Read String to JsonNode · GitHub
Read String to JsonNode · Raw · ReadStringToJsonNode.java · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Find elsewhere
🌐
Baeldung
baeldung.com › home › json › jackson › difference between astext() and tostring() in jsonnode
Difference Between asText() and toString() in JsonNode | Baeldung
April 7, 2025 - String json = "{\"name\":\"Joh...).isEqualTo("30"); String jsonText = node.asText(); assertThat(jsonText).isEmpty(); The toString() method is overridden from the Object and returns a String representation of the JsonNode‘s ...
🌐
Fasterxml
fasterxml.github.io › jackson-databind › javadoc › 2.7 › com › fasterxml › jackson › databind › JsonNode.html
JsonNode (jackson-databind 2.7.0 API)
Specified by: get in interface TreeNode · Returns: Node that represent value of the specified element, if this node is an array and has specified element. Null otherwise. public JsonNode get(String fieldName) Method for accessing value of the specified field of an object node.
🌐
Tpoint Tech
tpointtech.com › parsing-string-to-jsonnode-jackson
Parsing String to JsonNode Jackson - Tpoint Tech
March 17, 2025 - In this section, we will understand how we can use Jackson 2.0 for converting a JSON String to a JsonNode.
🌐
Davidsimpson
davidsimpson.me › 2017 › 01 › 09 › how-to-pretty-print-jsonnode-to-a-string-in-java
How to pretty print a JsonNode to a String in Java
Here’s a very simple way to pretty print a com.fasterxml.jackson.databind.JsonNode: public String prettyPrintJsonString(JsonNode jsonNode) { try { ObjectMapper mapper = new ObjectMapper(); Object json = mapper.readValue(jsonNode.toString(), Object.class); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json); } catch (Exception e) { return "Sorry, pretty print didn't work"; } }
🌐
Fasterxml
fasterxml.github.io › jackson-databind › javadoc › 2.8 › com › fasterxml › jackson › databind › JsonNode.html
JsonNode (jackson-databind 2.8.0 API)
Specified by: get in interface TreeNode · Returns: Node that represent value of the specified element, if this node is an array and has specified element. Null otherwise. public JsonNode get(String fieldName) Method for accessing value of the specified field of an object node.
🌐
Baeldung
baeldung.com › home › json › jackson › get all the keys in a json string using jsonnode
Get all the Keys in a JSON String Using JsonNode | Baeldung
May 11, 2024 - JsonParser creates a sequence of iterable tokens from the given JSON content. Token types are specified as enums in the JsonToken class, as listed below: ... While iterating using JsonParser, we can check the token type and perform required operations. Let’s fetch all the field names for our example JSON string: public List<String> getKeysInJsonUsingJsonParser(String json, ObjectMapper mapper) throws IOException { List<String> keys = new ArrayList<>(); JsonNode jsonNode = mapper.readTree(json); JsonParser jsonParser = jsonNode.traverse(); while (!jsonParser.isClosed()) { if (jsonParser.nextToken() == JsonToken.FIELD_NAME) { keys.add((jsonParser.getCurrentName())); } } return keys; }
🌐
Nim
nim-lang.org › docs › json.html
std/json
The parseJson procedure takes a string containing JSON and returns a JsonNode object. This is an object variant and it is either a JObject, JArray, JString, JInt, JFloat, JBool or JNull.
🌐
Baeldung
baeldung.com › home › json › jackson › working with tree model nodes in jackson
Working with Tree Model Nodes in Jackson | Baeldung
January 8, 2024 - This method is well covered in the Jackson – Marshall String to JsonNode article. Please refer to it for more info. A node may be converted from a Java object by calling the valueToTree(Object fromValue) method on the ObjectMapper: