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

     1  <!-- Code generated by gomarkdoc. DO NOT EDIT -->
     2  
     3  # sjson
     4  
     5  ```go
     6  import "github.com/fufuok/utils/xjson/sjson"
     7  ```
     8  
     9  Package sjson provides setting json values.
    10  
    11  ## Index
    12  
    13  - [func Delete(json, path string) (string, error)](<#func-delete>)
    14  - [func DeleteBytes(json []byte, path string) ([]byte, error)](<#func-deletebytes>)
    15  - [func Set(json, path string, value interface{}) (string, error)](<#func-set>)
    16  - [func SetBytes(json []byte, path string, value interface{}) ([]byte, error)](<#func-setbytes>)
    17  - [func SetBytesOptions(json []byte, path string, value interface{}, opts *Options) ([]byte, error)](<#func-setbytesoptions>)
    18  - [func SetOptions(json, path string, value interface{}, opts *Options) (string, error)](<#func-setoptions>)
    19  - [func SetRaw(json, path, value string) (string, error)](<#func-setraw>)
    20  - [func SetRawBytes(json []byte, path string, value []byte) ([]byte, error)](<#func-setrawbytes>)
    21  - [func SetRawBytesOptions(json []byte, path string, value []byte, opts *Options) ([]byte, error)](<#func-setrawbytesoptions>)
    22  - [func SetRawOptions(json, path, value string, opts *Options) (string, error)](<#func-setrawoptions>)
    23  - [type Options](<#type-options>)
    24  
    25  
    26  ## func Delete
    27  
    28  ```go
    29  func Delete(json, path string) (string, error)
    30  ```
    31  
    32  Delete deletes a value from json for the specified path.
    33  
    34  ## func DeleteBytes
    35  
    36  ```go
    37  func DeleteBytes(json []byte, path string) ([]byte, error)
    38  ```
    39  
    40  DeleteBytes deletes a value from json for the specified path.
    41  
    42  ## func Set
    43  
    44  ```go
    45  func Set(json, path string, value interface{}) (string, error)
    46  ```
    47  
    48  Set sets a json value for the specified path. A path is in dot syntax, such as "name.last" or "age". This function expects that the json is well\-formed, and does not validate. Invalid json will not panic, but it may return back unexpected results. An error is returned if the path is not valid.
    49  
    50  A path is a series of keys separated by a dot.
    51  
    52  \{ "name": \{"first": "Tom", "last": "Anderson"\}, "age":37, "children": \["Sara","Alex","Jack"\], "friends": \[ \{"first": "James", "last": "Murphy"\}, \{"first": "Roger", "last": "Craig"\} \] \} "name.last"          \>\> "Anderson" "age"                \>\> 37 "children.1"         \>\> "Alex"
    53  
    54  ## func SetBytes
    55  
    56  ```go
    57  func SetBytes(json []byte, path string, value interface{}) ([]byte, error)
    58  ```
    59  
    60  SetBytes sets a json value for the specified path. If working with bytes, this method preferred over Set\(string\(data\), path, value\)
    61  
    62  ## func SetBytesOptions
    63  
    64  ```go
    65  func SetBytesOptions(json []byte, path string, value interface{}, opts *Options) ([]byte, error)
    66  ```
    67  
    68  SetBytesOptions sets a json value for the specified path with options. If working with bytes, this method preferred over SetOptions\(string\(data\), path, value\)
    69  
    70  ## func SetOptions
    71  
    72  ```go
    73  func SetOptions(json, path string, value interface{}, opts *Options) (string, error)
    74  ```
    75  
    76  SetOptions sets a json value for the specified path with options. A path is in dot syntax, such as "name.last" or "age". This function expects that the json is well\-formed, and does not validate. Invalid json will not panic, but it may return back unexpected results. An error is returned if the path is not valid.
    77  
    78  ## func SetRaw
    79  
    80  ```go
    81  func SetRaw(json, path, value string) (string, error)
    82  ```
    83  
    84  SetRaw sets a raw json value for the specified path. This function works the same as Set except that the value is set as a raw block of json. This allows for setting premarshalled json objects.
    85  
    86  ## func SetRawBytes
    87  
    88  ```go
    89  func SetRawBytes(json []byte, path string, value []byte) ([]byte, error)
    90  ```
    91  
    92  SetRawBytes sets a raw json value for the specified path. If working with bytes, this method preferred over SetRaw\(string\(data\), path, value\)
    93  
    94  ## func SetRawBytesOptions
    95  
    96  ```go
    97  func SetRawBytesOptions(json []byte, path string, value []byte, opts *Options) ([]byte, error)
    98  ```
    99  
   100  SetRawBytesOptions sets a raw json value for the specified path with options. If working with bytes, this method preferred over SetRawOptions\(string\(data\), path, value, opts\)
   101  
   102  ## func SetRawOptions
   103  
   104  ```go
   105  func SetRawOptions(json, path, value string, opts *Options) (string, error)
   106  ```
   107  
   108  SetRawOptions sets a raw json value for the specified path with options. This furnction works the same as SetOptions except that the value is set as a raw block of json. This allows for setting premarshalled json objects.
   109  
   110  ## type Options
   111  
   112  Options represents additional options for the Set and Delete functions.
   113  
   114  ```go
   115  type Options struct {
   116      // Optimistic is a hint that the value likely exists which
   117      // allows for the sjson to perform a fast-track search and replace.
   118      Optimistic bool
   119      // ReplaceInPlace is a hint to replace the input json rather than
   120      // allocate a new json byte slice. When this field is specified
   121      // the input json will not longer be valid and it should not be used
   122      // In the case when the destination slice doesn't have enough free
   123      // bytes to replace the data in place, a new bytes slice will be
   124      // created under the hood.
   125      // The Optimistic flag must be set to true and the input must be a
   126      // byte slice in order to use this field.
   127      ReplaceInPlace bool
   128  }
   129  ```
   130  
   131  
   132  
   133  Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)