neatjson

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: MIT Imports: 4 Imported by: 1

README

GitHub Workflow Status (branch) GoDoc Coverage Status Supported Go Versions GitHub Release Go Report Card

neatjson

neatjson make it neat to use "encoding/json" in golang.

CHINESE README

中文说明

Installation

go get github.com/yyle88/neatjson

Features

  • Convert Go structures to indented JSON strings.
  • Format JSON data from raw strings, byte arrays.

Usage

Here's an example of how to format a Go data structure into a indented JSON string:

package main

import (
	"fmt"
	"github.com/yyle88/neatjson/neatjsons"
)

func main() {
	arg := map[string]any{"a": "abc", "n": 123}
	res := neatjsons.S(arg)

	fmt.Println(res)
}

Output:

{
	"a": "abc",
	"n": 123
}

License

neatjson is open-source and released under the MIT License. See the LICENSE file for more information.


Support

Welcome to contribute to this project by submitting pull requests or reporting issues.

If you find this package helpful, give it a star on GitHub!

Thank you for your support!

Happy Coding with neatjson! 🎉

Give me stars. Thank you!!!

See stars

see stars

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TAB = NewNeatjson("", "\t")
	SP0 = NewNeatjson("", "")
	SP1 = NewNeatjson("", " ")
	SP2 = NewNeatjson("", "  ")
	SP3 = NewNeatjson("", "   ")
	SP4 = NewNeatjson("", "    ")

	NOI = notNeatjson() //在转json时结果不换行
	NON = notNeatjson() //在转json时结果不换行
)

这里定义些 常用常量 以便于外部直接使用

Functions

This section is empty.

Types

type Neatjson

type Neatjson struct {
	// contains filtered or unexported fields
}

Neatjson implements various syntactic sugar to convert Go structs into JSON strings. The purpose of this package is to provide neat, indented JSON representations. Neatjson 实现了一些简单的语法糖,用于将 Go 的结构体转换为 JSON 字符串。 neat 的含义包括:整齐的、工整的、简洁的、整洁的。

func NewNeatjson

func NewNeatjson(prefix string, indent string) *Neatjson

NewNeatjson creates a new instance of Neatjson with the specified prefix and indent. NewNeatjson 根据指定的前缀和缩进字符创建一个 Neatjson 实例。

func (*Neatjson) B

func (N *Neatjson) B(v interface{}) ([]byte, error)

B is a shorthand for Bytes. B 是 Bytes 方法的简写。

func (*Neatjson) B2S

func (N *Neatjson) B2S(data []byte) (string, error)

B2S converts JSON bytes into a neat JSON string. "2" means "to". B2S 将 JSON 字节数组转换为整齐的 JSON 字符串。"2" 表示 "to"。

func (*Neatjson) BxB

func (N *Neatjson) BxB(data []byte) ([]byte, error)

BxB converts a JSON byte array into a neat JSON byte array with the desired formatting. BxB 将 JSON 字节数组转换为符合要求格式的整齐 JSON 字节数组。

func (*Neatjson) BxS

func (N *Neatjson) BxS(data string) ([]byte, error)

BxS converts a JSON string into a neat JSON byte array. "x" means "from". BxS 将 JSON 字符串转换为整齐的 JSON 字节数组。"x" 表示 "from"。

func (*Neatjson) Bytes

func (N *Neatjson) Bytes(v interface{}) ([]byte, error)

Bytes converts a struct to a JSON byte array, similar to "json.Marshal" but supports indentation. Bytes 将结构体转换为 JSON 字节数组,与 "json.Marshal" 类似,但支持缩进。

func (*Neatjson) Must

func (N *Neatjson) Must() *Neatjson_Must

func (*Neatjson) Omit

func (N *Neatjson) Omit() *Neatjson_Omit

func (*Neatjson) S

func (N *Neatjson) S(v interface{}) (string, error)

S is a shorthand for Sjson. S 是 Sjson 方法的简写。

func (*Neatjson) S2B

func (N *Neatjson) S2B(data string) ([]byte, error)

S2B converts a JSON string into a neat JSON byte array. "2" means "to". S2B 将 JSON 字符串转换为整齐的 JSON 字节数组。"2" 表示 "to"。

func (*Neatjson) Sjson

func (N *Neatjson) Sjson(v interface{}) (string, error)

Sjson converts a struct to a JSON string with the desired formatting. Sjson 将结构体转换为符合要求格式的 JSON 字符串。

func (*Neatjson) Soft

func (N *Neatjson) Soft() *Neatjson_Soft

func (*Neatjson) SxB

func (N *Neatjson) SxB(data []byte) (string, error)

SxB converts a JSON byte array into a neat JSON string. "x" means "from". SxB 将 JSON 字节数组转换为整齐的 JSON 字符串。"x" 表示 "from"。

func (*Neatjson) SxS

func (N *Neatjson) SxS(s string) (string, error)

SxS converts a JSON string into a neat JSON string with the desired formatting. SxS 将 JSON 字符串转换为符合要求格式的整齐 JSON 字符串。

type Neatjson_Must

type Neatjson_Must struct{ N *Neatjson }

func (*Neatjson_Must) B

func (T *Neatjson_Must) B(v interface{}) (res []byte)

func (*Neatjson_Must) B2S

func (T *Neatjson_Must) B2S(data []byte) (res string)

func (*Neatjson_Must) BxB

func (T *Neatjson_Must) BxB(data []byte) (res []byte)

func (*Neatjson_Must) BxS

func (T *Neatjson_Must) BxS(data string) (res []byte)

func (*Neatjson_Must) Bytes

func (T *Neatjson_Must) Bytes(v interface{}) (res []byte)

func (*Neatjson_Must) S

func (T *Neatjson_Must) S(v interface{}) (res string)

func (*Neatjson_Must) S2B

func (T *Neatjson_Must) S2B(data string) (res []byte)

func (*Neatjson_Must) Sjson

func (T *Neatjson_Must) Sjson(v interface{}) (res string)

func (*Neatjson_Must) SxB

func (T *Neatjson_Must) SxB(data []byte) (res string)

func (*Neatjson_Must) SxS

func (T *Neatjson_Must) SxS(s string) (res string)

type Neatjson_Omit

type Neatjson_Omit struct{ N *Neatjson }

func (*Neatjson_Omit) B

func (T *Neatjson_Omit) B(v interface{}) (res []byte)

func (*Neatjson_Omit) B2S

func (T *Neatjson_Omit) B2S(data []byte) (res string)

func (*Neatjson_Omit) BxB

func (T *Neatjson_Omit) BxB(data []byte) (res []byte)

func (*Neatjson_Omit) BxS

func (T *Neatjson_Omit) BxS(data string) (res []byte)

func (*Neatjson_Omit) Bytes

func (T *Neatjson_Omit) Bytes(v interface{}) (res []byte)

func (*Neatjson_Omit) S

func (T *Neatjson_Omit) S(v interface{}) (res string)

func (*Neatjson_Omit) S2B

func (T *Neatjson_Omit) S2B(data string) (res []byte)

func (*Neatjson_Omit) Sjson

func (T *Neatjson_Omit) Sjson(v interface{}) (res string)

func (*Neatjson_Omit) SxB

func (T *Neatjson_Omit) SxB(data []byte) (res string)

func (*Neatjson_Omit) SxS

func (T *Neatjson_Omit) SxS(s string) (res string)

type Neatjson_Soft

type Neatjson_Soft struct{ N *Neatjson }

func (*Neatjson_Soft) B

func (T *Neatjson_Soft) B(v interface{}) (res []byte)

func (*Neatjson_Soft) B2S

func (T *Neatjson_Soft) B2S(data []byte) (res string)

func (*Neatjson_Soft) BxB

func (T *Neatjson_Soft) BxB(data []byte) (res []byte)

func (*Neatjson_Soft) BxS

func (T *Neatjson_Soft) BxS(data string) (res []byte)

func (*Neatjson_Soft) Bytes

func (T *Neatjson_Soft) Bytes(v interface{}) (res []byte)

func (*Neatjson_Soft) S

func (T *Neatjson_Soft) S(v interface{}) (res string)

func (*Neatjson_Soft) S2B

func (T *Neatjson_Soft) S2B(data string) (res []byte)

func (*Neatjson_Soft) Sjson

func (T *Neatjson_Soft) Sjson(v interface{}) (res string)

func (*Neatjson_Soft) SxB

func (T *Neatjson_Soft) SxB(data []byte) (res string)

func (*Neatjson_Soft) SxS

func (T *Neatjson_Soft) SxS(s string) (res string)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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