jsonx

package
v0.0.0-...-d0ebcda Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: BSD-3-Clause Imports: 11 Imported by: 3

Documentation

Index

Examples

Constants

View Source
const (
	StatusOKUri       = "urn:status:ok"
	StatusNotFoundUri = "urn:status:notfound"
	StatusTimeoutUri  = "urn:status:timeout"
)

Variables

This section is empty.

Functions

func Indent

func Indent(body io.ReadCloser, h http.Header, prefix, indent string) (io.ReadCloser, *core.Status)
Example
package main

import (
	"bytes"
	"fmt"
	"github.com/behavioral-ai/core/iox"
	"io"
)

const (
	customerAddr = "file://[cwd]/test/customer-address.txt"
)

func main() {
	buf, status := iox.ReadFile(customerAddr)
	fmt.Printf("test: iox.ReadFile() -> [status:%v] %v\n", status, string(buf))

	if status.OK() {
		//fmt.Printf("test:")
		c := io.NopCloser(bytes.NewReader(buf))
		c2, status1 := Indent(c, nil, "", "  ")
		if status1.OK() {
			buf2, status := iox.ReadAll(c2, nil)
			fmt.Printf("test: Indent() -> [status:%v] %v\n", status, string(buf2))
		}
	}

}
Output:

test: iox.ReadFile() -> [status:OK] [{"customer-id":"C001","created-ts":"0001-01-01T00:00:00Z","address-1":"1514 Cedar Ridge Road","address-2":"","city":"Vinton","state":"IA","postal-code":"52349","email":"before-email@hotmail.com"}]
test: Indent() -> [status:OK] [
 {
   "customer-id": "C001",
   "created-ts": "0001-01-01T00:00:00Z",
   "address-1": "1514 Cedar Ridge Road",
   "address-2": "",
   "city": "Vinton",
   "state": "IA",
   "postal-code": "52349",
   "email": "before-email@hotmail.com"
 }
]

func Marshal

func Marshal(v any) ([]byte, *core.Status)

func New

func New[T any](v any, h http.Header) (t T, status *core.Status)

New - create a new type from JSON content, supporting: string, *url.URL, []byte, io.Reader, io.ReadCloser

func NewReadCloser

func NewReadCloser(v any) (io.ReadCloser, int64, *core.Status)

NewReadCloser - create an io.ReadCloser from a type

func NewStatusFrom

func NewStatusFrom(uri string) *core.Status

NewStatusFrom - create a new Status from a URI

Types

This section is empty.

Jump to

Keyboard shortcuts

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