package
0.1.3
Repository: https://github.com/mkideal/pkg.git
Documentation: pkg.go.dev

# README

jsonx - json pkg supports comments,extraComma,unquotedKey

example 1: WithComment,WithExtraComma

{
	/* c-style comment supported if contains option WithComment
	 * extra comma allowed if contains option WithExtraComma
	 */
	// a is an object
	"a": {
		// id is an integer
		"id": 1,
		// name is a string
		"name": "xxx", // name of A
	},
	"b": {
		"key": "key",
		"value": 222, // NOTE: here is an extra comma, but no problem if contains option WithExtraComma
	},
	"x": 2,
	"y": 1.5,
	"z": true,
	"s": [
		// array element 0
		{"key":"k1", "value": 1},
		// array element 1
		{
			"key":"k2",
			"value":2
		},{} // array element 2
	]
}

example 2: WithComment,WithExtraComma,WithUnquotedKey

{
	/* c-style comment supported if contains option WithComment
	 * extra comma allowed if contains option WithExtraComma
	 * key not quoted with " allowed if contains option WithUnquotedKey
	 */
	// a is an object
	a: {
		// id is an integer
		id: 1,
		// name is a string
		name: "xxx", // name of A
	},
	b: {
		key: "key",
		value: 222, // NOTE: here is an extra comma, but no problem if contains option WithExtraComma
	},
	x: 2,
	y: 1.5,
	z: true,
	s: [
		// array element 0
		{key:"k1", value: 1},
		// array element 1
		{
			key:"k2",
			value:2
		},{} // array element 2
	]
}

# Functions

Marshal marshal value v to json with options.
NewDecoder creates a decoder with reader and options.
NewEncoder wraps json.NewEncoder.
Read reads a json node from reader r.
ReadBytes reads a json node from bytes.
ReadFile reads a json node from file.
Unmarshal wraps json.Unmarshal with options.
WithComment returns an option which sets supportComment true.
WithExtraComma returns an option which sets extraComma true.
WithIndent returns an option which with indent while outputing.
WithPrefix returns an option which with prefix while outputing.
WithUnquotedKey returns an option which sets unquotedKey true.
Write writes a json node to writer w.
WriteFile writer a json node to file.

# Structs

Decoder wraps json.Decoder with options.

# Interfaces

Node represents top-level json object.

# Type aliases

Option represents a function for setting options.