ziggy fmt

Formats Ziggy Documents and Ziggy Schemas.

It’s highly recommended you enable format on save in your editor to get the most out of the autoformatter.

Trailing Commas

Trailing commas in structs, dicts, and arrays tell the autoformatter to perform vertical alignment.

Lack of a trailing comma requests horizontal alignment instead.

Given this Ziggy document:

.foo = "bar", .bar = [1, 
2, 3], .baz = true,

This is the autoformatted result:

.foo = "bar",
.bar = [1, 2, 3],
.baz = true,
  • the outer struct was vertically aligned because of the trailing comma
  • the array value of bar was horizontally aligned because there was no comma after 3

Similar behavior also applies to Ziggy Schemas.

Upgrading Dictionaries

If a Ziggy document has a dict value in it, you can give it a . to have ziggy fmt turn it into a struct.

Given this Ziggy document:

.foo = "bar",
.bar = {
  "arst": true,
  "qwfp": {
    "another": "dict",
    "nested": "more deeply",
  },
}

Give a . to the value of bar:

.foo = "bar",
.bar = .{ // <----- here!
  "arst": true,
  "qwfp": {
    "another": "dict",
    "nested": "more deeply",
  },
}

On save the autoformatter will turn all dict-style fields into struct-style fields:

.foo = "bar",
.bar = .{
  .arst = true,
  .qwfp = {
    "another": "dict",
    "nested": "more deeply",
  },
}

Note how the innermost dictionary was not transformed.

Ziggy Documents are a superset of JSON, and you can both use ziggy fmt and ziggy convert to help you upgrade your JSON documents to Ziggy Documents.

Downgrading Structs

By removing the . in front of a struct you can have ziggy fmt apply the inverse transformation to what you saw above.

But why would you? More structs, more glory!