github.com/fufuok/utils@v1.0.10/xjson/pretty/DOC.md (about)

     1  <!-- Code generated by gomarkdoc. DO NOT EDIT -->
     2  
     3  # pretty
     4  
     5  ```go
     6  import "github.com/fufuok/utils/xjson/pretty"
     7  ```
     8  
     9  ## Index
    10  
    11  - [Variables](<#variables>)
    12  - [func Color(src []byte, style *Style) []byte](<#func-color>)
    13  - [func Pretty(json []byte) []byte](<#func-pretty>)
    14  - [func PrettyOptions(json []byte, opts *Options) []byte](<#func-prettyoptions>)
    15  - [func Spec(src []byte) []byte](<#func-spec>)
    16  - [func SpecInPlace(src []byte) []byte](<#func-specinplace>)
    17  - [func Ugly(json []byte) []byte](<#func-ugly>)
    18  - [func UglyInPlace(json []byte) []byte](<#func-uglyinplace>)
    19  - [type Options](<#type-options>)
    20  - [type Style](<#type-style>)
    21  
    22  
    23  ## Variables
    24  
    25  DefaultOptions is the default options for pretty formats.
    26  
    27  ```go
    28  var DefaultOptions = &Options{Width: 80, Prefix: "", Indent: "  ", SortKeys: false}
    29  ```
    30  
    31  ## func Color
    32  
    33  ```go
    34  func Color(src []byte, style *Style) []byte
    35  ```
    36  
    37  Color will colorize the json. The style parma is used for customizing the colors. Passing nil to the style param will use the default TerminalStyle.
    38  
    39  ## func Pretty
    40  
    41  ```go
    42  func Pretty(json []byte) []byte
    43  ```
    44  
    45  Pretty converts the input json into a more human readable format where each element is on it's own line with clear indentation.
    46  
    47  ## func PrettyOptions
    48  
    49  ```go
    50  func PrettyOptions(json []byte, opts *Options) []byte
    51  ```
    52  
    53  PrettyOptions is like Pretty but with customized options.
    54  
    55  ## func Spec
    56  
    57  ```go
    58  func Spec(src []byte) []byte
    59  ```
    60  
    61  Spec strips out comments and trailing commas and convert the input to a valid JSON per the official spec: https://tools.ietf.org/html/rfc8259
    62  
    63  The resulting JSON will always be the same length as the input and it will include all of the same line breaks at matching offsets. This is to ensure the result can be later processed by a external parser and that that parser will report messages or errors with the correct offsets.
    64  
    65  ## func SpecInPlace
    66  
    67  ```go
    68  func SpecInPlace(src []byte) []byte
    69  ```
    70  
    71  SpecInPlace is the same as Spec, but this method reuses the input json buffer to avoid allocations. Do not use the original bytes slice upon return.
    72  
    73  ## func Ugly
    74  
    75  ```go
    76  func Ugly(json []byte) []byte
    77  ```
    78  
    79  Ugly removes insignificant space characters from the input json byte slice and returns the compacted result.
    80  
    81  ## func UglyInPlace
    82  
    83  ```go
    84  func UglyInPlace(json []byte) []byte
    85  ```
    86  
    87  UglyInPlace removes insignificant space characters from the input json byte slice and returns the compacted result. This method reuses the input json buffer to avoid allocations. Do not use the original bytes slice upon return.
    88  
    89  ## type Options
    90  
    91  Options is Pretty options
    92  
    93  ```go
    94  type Options struct {
    95      // Width is an max column width for single line arrays
    96      // Default is 80
    97      Width int
    98      // Prefix is a prefix for all lines
    99      // Default is an empty string
   100      Prefix string
   101      // Indent is the nested indentation
   102      // Default is two spaces
   103      Indent string
   104      // SortKeys will sort the keys alphabetically
   105      // Default is false
   106      SortKeys bool
   107  }
   108  ```
   109  
   110  ## type Style
   111  
   112  Style is the color style
   113  
   114  ```go
   115  type Style struct {
   116      Key, String, Number [2]string
   117      True, False, Null   [2]string
   118      Escape              [2]string
   119      Append              func(dst []byte, c byte) []byte
   120  }
   121  ```
   122  
   123  TerminalStyle is for terminals
   124  
   125  ```go
   126  var TerminalStyle *Style
   127  ```
   128  
   129  
   130  
   131  Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)