pretty

package module
v0.0.0-...-7527252 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2023 License: GPL-3.0 Imports: 7 Imported by: 0

README

pretty GoDoc Go Report

Installing

$ go get -u github.com/zc310/pretty

Pretty

Using this example:

{
  "firstName": "John",
  "lastName": "Smith",
  "isAlive": true,
  "age": 27,
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postalCode": "10021-3100"
  },
  "phoneNumbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "office",
      "number": "646 555-4567"
    }
  ],
  "children": [
    "Catherine",
    "Thomas",
    "Trevor"
  ],
  "spouse": null
}

The following code:

result = pretty.Format(example)

Will format the json to:

{
  "firstName":"John",
  "lastName":"Smith",
  "isAlive":true,
  "age":27,
  "address":{"streetAddress":"21 2nd Street","city":"New York","state":"NY","postalCode":"10021-3100"},
  "phoneNumbers":[{"type":"home","number":"212 555-1234"},{"type":"office","number":"646 555-4567"}],
  "children":["Catherine","Thomas","Trevor"],
  "spouse":null
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = &Options{Indent: "  ", MaxDepth: 1, MinDepth: 1}

Functions

func Format

func Format(o any) []byte

func FormatOptions

func FormatOptions(json []byte, opts *Options) []byte

Types

type Options

type Options struct {
	Indent   string
	MaxDepth int
	MinDepth int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL