load json, dump yaml: output includes curly braces

Issue #359 closed
Mark Bucciarelli
created an issue

I am converting from json to yaml using this pattern:

Yaml yaml = new Yaml();
Map<String, Object> map = (Map<String, Object>) yaml.load(json);
return yaml.dump(map);

For the following value of json variable:

{
  "type" : "object",
  "id" : "urn:jsonschema:com:example:openapi:SimpleBean",
  "properties" : {
    "id" : {
      "type" : "integer"
    },
    "name" : {
      "type" : "string"
    }
  }
}

I get the following output:

type: object
id: urn:jsonschema:com:example:openapi:SimpleBean
properties:
  id: {type: integer}
  name: {type: string}

When I try the on-line converter for this input (https://www.json2yaml.com/), I get the yaml output that I expected:

---
type: object
id: urn:jsonschema:com:example:openapi:SimpleBean
properties:
  id:
    type: integer
  name:
    type: string

Can I make snakeyaml dump() generate this output?

Comments (4)

  1. Andrey Somov repo owner
    1. Is it a bug ? Why not to use mailing list or stackoverflow ?
    2. YAML format is a way more flexible than JSON. Try this:
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(FlowStyle.BLOCK);
    
  2. Mark Bucciarelli reporter

    That worked. Thank you.

    I considered it a bug because I did not expect that the dumper would treat exteral map differently than an internal map.

    But that is up to you!

    P.S. I have no stack overflow account.

  3. Log in to comment