Convert longhand YAML syntax to shorthand YAML syntax

I have a YAML file that has been written in the long syntax

children:
  -
    type: section
    subtype: false
    title: Top-wrapper
    attributes: {  }
    children:
      -
        type: section
        subtype: false
        title: Second-wrapper
        attributes: {  }
        children:
          -
            type: section
            subtype: false
            title: Header
            attributes: {  }
            children:
              -
                type: container
                subtype: false
                title: Untitled
                attributes: {  }
                children:
                  -
                    type: grid
                    subtype: false
                    title: Untitled
                    attributes: {  }
                    children:
                      -
                        type: block
                        subtype: false
                        title: Untitled
                        attributes:
                          size: 100
                        children:
                          -
                            type: spacer
                            subtype: false
                            title: Spacer
                            attributes:
                              enabled: 1
                            children: {  }
          -
            type: section
            subtype: false
            title: Navigation
            attributes: {  }
            children:
              -
                type: container
                subtype: false
                title: Untitled
                attributes: {  }
                children:
                  -
                    type: grid
                    subtype: false
                    title: Untitled
                    attributes: {  }
                    children:
                      -
                        type: block
                        subtype: false
                        title: Untitled
                        attributes:
                          size: 100
                        children:
                          -
                            type: spacer
                            subtype: false
                            title: Spacer
                            attributes:
                              enabled: 1
                            children: {  }
      -
        type: section
        subtype: false
        title: Showcase
        attributes: {  }
        children:
          -
            type: container
            subtype: false
            title: Untitled
            attributes: {  }
            children:
              -
                type: grid
                subtype: false
                title: Untitled
                attributes: {  }
                children:
                  -
                    type: block
                    subtype: false
                    title: Untitled
                    attributes:
                      size: 100
                    children:
                      -
                        type: spacer
                        subtype: false
                        title: Spacer
                        attributes:
                          enabled: 1
                        children: {  }
  -
    type: section
    subtype: false
    title: Feature
    attributes: {  }
    children:
      -
        type: container
        subtype: false
        title: Untitled
        attributes: {  }
        children:
          -
            type: grid
            subtype: false
            title: Untitled
            attributes: {  }
            children:
              -
                type: block
                subtype: false
                title: Untitled
                attributes:
                  size: 100
                children:
                  -
                    type: spacer
                    subtype: false
                    title: Spacer
                    attributes:
                      enabled: 1
                    children: {  }
  -
    type: section
    subtype: false
    title: Main-content
    attributes: {  }
    children:
      -
        type: grid
        subtype: false
        title: Untitled
        attributes: {  }
        children:
          -
            type: block
            subtype: false
            title: Untitled
            attributes:
              size: 20
            children:
              -
                type: section
                subtype: false
                title: Sidebar-left
                attributes: {  }
                children:
                  -
                    type: grid
                    subtype: false
                    title: Untitled
                    attributes: {  }
                    children:
                      -
                        type: block
                        subtype: false
                        title: Untitled
                        attributes:
                          size: 100
                        children:
                          -
                            type: position
                            subtype: false
                            title: Sidebar-left
                            attributes:
                              enabled: 1
                              key: sidebar-left
                              title: Sidebar-left
                            children: {  }
          -
            type: block
            subtype: false
            title: Untitled
            attributes:
              size: 60
            children:
              -
                type: section
                subtype: false
                title: Main
                attributes: {  }
                children:
                  -
                    type: grid
                    subtype: false
                    title: Untitled
                    attributes: {  }
                    children:
                      -
                        type: block
                        subtype: false
                        title: Untitled
                        attributes:
                          size: 100
                        children:
                          -
                            type: pagecontent
                            subtype: false
                            title: Pagecontent
                            attributes:
                              enabled: 1
                            children: {  }
          -
            type: block
            subtype: false
            title: Untitled
            attributes:
              size: 20
            children:
              -
                type: section
                subtype: false
                title: Sidebar-right
                attributes: {  }
                children:
                  -
                    type: grid
                    subtype: false
                    title: Untitled
                    attributes: {  }
                    children:
                      -
                        type: block
                        subtype: false
                        title: Untitled
                        attributes:
                          size: 100
                        children:
                          -
                            type: position
                            subtype: false
                            title: Sidebar-right
                            attributes:
                              enabled: 1
                              key: sidebar-right
                              title: Sidebar-right
                            children: {  }
  -
    type: section
    subtype: false
    title: Subfeature
    attributes: {  }
    children:
      -
        type: container
        subtype: false
        title: Untitled
        attributes: {  }
        children:
          -
            type: grid
            subtype: false
            title: Untitled
            attributes: {  }
            children:
              -
                type: block
                subtype: false
                title: Untitled
                attributes:
                  size: 100
                children:
                  -
                    type: spacer
                    subtype: false
                    title: Spacer
                    attributes:
                      enabled: 1
                    children: {  }
  -
    type: section
    subtype: false
    title: Footer
    attributes: {  }
    children:
      -
        type: container
        subtype: false
        title: Untitled
        attributes: {  }
        children:
          -
            type: grid
            subtype: false
            title: Untitled
            attributes: {  }
            children:
              -
                type: block
                subtype: false
                title: Untitled
                attributes:
                  size: 100
                children:
                  -
                    type: spacer
                    subtype: false
                    title: Spacer
                    attributes:
                      enabled: 1
                    children: {  }
  -
    type: offcanvas
    subtype: false
    title: Offcanvas
    attributes:
      name: 'Offcanvas Section'
    children: {  }
  -
    type: atoms
    subtype: false
    title: Atoms
    attributes:
      name: 'Atoms Section'
    children:
      -
        type: grid
        subtype: false
        title: Untitled
        attributes: {  }
        children: {  }

I would like to convert it to use the shorthand syntax similar to this

layout:
  1:
   - top-wrapper 100:
      header:
        container:
          - spacer

      navigation:
        container:
          - [particle-logo 20, particle-menu 80]

      showcase:
        container:
          - spacer

  feature:
    container:
      - spacer

  main:
    container:
      - system-messages
      - pagecontent

  footer:
    container:
      - spacer

  debug:
    container:
      - spacer

  offcanvas:
    - particle-mobile-menu

I am a bit confused about how I can do that. I know YAML has certain rules about using the shorthand syntax, but I can’t make head or tails about them, and I haven’t found a good tutorial or cheatsheet to help me better understand that.

Any assistance would be appreciated.


Source: syntax

Leave a Reply