Convert Json To Yaml In Java

In java, to convert json string or json object to yaml string, you can use jackson to do this

    public String toYamlString(String jsonString) throws JsonProcessingException, IOException {
        // parse JSON
        JsonNode jsonNodeTree = new ObjectMapper().readTree(jsonString);
        return new YAMLMapper().writeValueAsString(jsonNodeTree);;

in pom.xml, add dependency


Leave a Reply

Your email address will not be published. Required fields are marked *