Skip to main content
added 21 characters in body
Source Link
xdhmoore
  • 10.2k
  • 12
  • 57
  • 103

The indentation in YAML is tricky (and it matters), so I've found the above and similar tools helpful to get what I want. It also helps me to think about YAML in terms of lists and objects and strings. Here - creates a new item in a list, and type: bind is a key-value in that item (not in the list). Then source: blarg is also a key-value in the same item, so it makes sense that theyit should line up with the t in type. Indenting more indicates you are continuing a multiline string, and I think if you indented less (like aligning with -), you would get an error or end up adding a key-value pair to one of the objects higher up the hierarchy.

The indentation in YAML is tricky (and it matters), so I've found the above and similar tools helpful to get what I want. It also helps me to think about YAML in terms of lists and objects and strings. Here - creates a new item in a list, and type: bind is a key-value in that item (not in the list). Then source: blarg is also a key-value in the same item, so it makes sense that they should line up. Indenting more indicates you are continuing a multiline string, and I think if you indented less (like aligning with -), you would get an error or end up adding a key-value pair to one of the objects higher up the hierarchy.

The indentation in YAML is tricky (and it matters), so I've found the above and similar tools helpful to get what I want. It also helps me to think about YAML in terms of lists and objects and strings. Here - creates a new item in a list, and type: bind is a key-value in that item (not in the list). Then source: blarg is also a key-value in the same item, so it makes sense that it should line up with the t in type. Indenting more indicates you are continuing a multiline string, and I think if you indented less (like aligning with -), you would get an error or end up adding a key-value pair to one of the objects higher up the hierarchy.

Source Link
xdhmoore
  • 10.2k
  • 12
  • 57
  • 103

This is based on the YAML in your answer. When I plug it into this yaml to json converter, I get:

{ "version": "3.2", "services": null, "api_service": { "build": "./api_service", "restart": "always", "ports": [ { "target": "8080\npublished: 8080" } ], "depends_on": [ "postgres_db" ], "links": [ "postgres_db:yarmp-db-host" ], "volumes": [ { "type": "bind\nsource: /data/yarmp-data" } ] }, "postgres_db": { "build": "./postgres_db", "restart": "always", "ports": [ { "target": "5432\npublished: 5432" } ], "env_file": [ "postgres_db/pg-db-database.env" ], "volumes": [ "database-data:/var/lib/postgresql/data/" ] }, "volumes": { "database-data": null } } 

You can see several places where the result is something like "type": "bind\nsource: /data/yarmp-data". It appears that YAML is interpreting the source line here as the 2nd line of a multiline string. However, if you adjust the indentation to line up with the t in - type, you end up with:

... "volumes": [ { "type": "bind", "source": "/data/yarmp-data", "target": "/data/yarmp-data" } ] ... 

The indentation in YAML is tricky (and it matters), so I've found the above and similar tools helpful to get what I want. It also helps me to think about YAML in terms of lists and objects and strings. Here - creates a new item in a list, and type: bind is a key-value in that item (not in the list). Then source: blarg is also a key-value in the same item, so it makes sense that they should line up. Indenting more indicates you are continuing a multiline string, and I think if you indented less (like aligning with -), you would get an error or end up adding a key-value pair to one of the objects higher up the hierarchy.

Anyway, it's certainly confusing. I've found such online tools to be helpful.