Upgrade to Pro — share decks privately, control downloads, hide ads and more …

YAML - An unfortunate series of indents

YAML - An unfortunate series of indents

Get a full briefing on the history of YAML and hot tips for the best tools for linting and editing the markup language in your favorite editors.

B5a1b84c06bcad998068fc5557e3c8d9?s=128

Keith Resar

April 18, 2019
Tweet

Transcript

  1. YAML: ain’t: markup: - language @KeithResar

  2. An: unfortunate: series: of: - indents @KeithResar

  3. None
  4. @KeithResar

  5. @KeithResar

  6. None
  7. None
  8. @KeithResar ANSIBLE YAML --- - hosts: localhost tasks: - debug:

    msg: "Hello World"
  9. @KeithResar KUBERNETES YAML --- apiVersion: v1 kind: Pod metadata: ...

    spec: ... status: ...
  10. @KeithResar CALENZEN YAML --- name: Zoom US Level 1 (2018-09-05)

    level: 1 priority: 102 driver: RegexV1 key_type: ... detect_regex: … output: ...
  11. None
  12. None
  13. @KeithResar RFC 822 From: root@example.com To: john@example.com, ∙ ∙ ∙

    "jane@example.com" Unstructured Text Key/Value pairs Multi-line folding CRLF followed by LWSP character Delimiting and Quoting Optional, not part of string, c-style escape sequences
  14. @KeithResar OTHER PRIOR ART • Indentation-based scoping from Python •

    End of line normalization from HTML • Collections & scalar data types from Perl, Python, Ruby • Incremental interfaces and streaming one-pass interfaces supports large documents
  15. @KeithResar COMPARING YAML WITH JSON • Simplicity & universality •

    Lowest common denominator • Trivial to generate and parse JSON • Human readability • Arbitrary native data structures • Complex processing across environments YAML
  16. @KeithResar YAML ⊇ JSON JSON's RFC4627 requires that mappings keys

    merely “SHOULD” be unique, while YAML insists they “MUST” be. Technically, YAML therefore complies with the JSON spec, choosing to treat duplicates as an error. In practice, since JSON is silent on the semantics of such duplicates, the only portable JSON files are those with unique keys, which are therefore valid YAML files.
  17. None
  18. None
  19. @KeithResar QUOTING --- plain: look ma no quotes, but the

    most limited single_quotes: - 'keith''s single quotes' - 'bare \ is ok' double_quotes: - "only flow that can express arbitrary strings" - "\\ escape sequences, but must quote \" and \\"
  20. @KeithResar BLOCKS --- # literal style - a: | multi-line

    ∙ ∙ ∙ text block # folded style - b: > multi-line ∙ ∙ ∙ text block Becomes: multi-line Text block Becomes: Multi-line text block
  21. @KeithResar BLOCK CHOMPING --- # clip (default) - includes final

    line break - a: | text # strip - excludes final line break & trailing empty lines - a: |- text # keep - includes all trailing line breaks - a: |+ text
  22. None
  23. None
  24. @KeithResar DIRECTIVES --- <document content> --- <document content> ... Start

    of Stream Separate directives from content End of Document Used for streaming comm channels
  25. @KeithResar TAGS IN _FAILSAFE_ SCHEMA --- - just a string

    - true - a: 1 b: 2 - - a - b
  26. @KeithResar TAGS IN _FAILSAFE_ SCHEMA --- - !!str just a

    string - !!str true - !!map a: 1 b: 2 - !!seq - a - b
  27. @KeithResar TAGS IN _JSON_ SCHEMA --- - just a string

    - true - a: 1 b: 2 - - a - b
  28. @KeithResar TAGS IN _CUSTOM_ SCHEMA %TAG !foo! tag:example.com,2002: --- invoice1:

    !foo!invoice ... invoice2: !<tag:example.com,2002:invoice> ...
  29. @KeithResar

  30. None
  31. None
  32. @KeithResar

  33. @KeithResar LINTING • YMMV re: quality - check web and

    python • yamllint • ansible-lint
  34. @KeithResar EDITORS • vim • Atom • Eclipse • Visual

    Studio Code
  35. None
  36. None
  37. @KeithResar GO FARTHER WITH THESE _RESOURCES_ YAML Ain’t Markup Language

    (YAML™) Version 1.2 Spec https://yaml.org/spec/1.2/spec.html Ansible Lint Documentation https://docs.ansible.com/ansible-lint/
  38. None
  39. THANKS @KeithResar