jsonconv

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2021 License: BSD-3-Clause Imports: 3 Imported by: 1

README

jsonconv

In the go standard library, encoding/json contains utility functions for encoding and decoding JSON literal strings, but they are unexported. jsonconv provides these functions for use with other software.

The implementations are current as of go 1.16.

Example

// decoding
quoted := []byte(`"foo \"bar\""`)
str, ok := jsonconv.Unquote(quoted)
// str should be `foo "bar"`
// ...

// encoding
unquoted := `a \ b`
jsonBytes := jsonconv.AppendQuote(nil, unquoted)
// jsonBytes should be []byte(`"a \\ b"`)
// ...

Why Not strconv?

strconv provides Quote and Unquote functions, but they are intended for handling go literal strings, which are not the same as JSON literal strings.

Documentation

API documentation is available at: https://pkg.go.dev/github.com/7fffffff/jsonconv

License

BSD-3-Clause, same as the go standard library.

Documentation

Overview

Package jsonconv provides functions to encode and decode JSON string literals

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendQuote

func AppendQuote(dest []byte, s string) []byte

AppendQuote appends the string s to dest as a quoted JSON string literal, escaping as necessary.

func AppendQuoteBytes

func AppendQuoteBytes(dest, s []byte) []byte

AppendQuoteBytes appends the string stored in s to dest as a quoted JSON string literal, escaping as necessary.

func AppendQuoteBytesEscapeHTML

func AppendQuoteBytesEscapeHTML(dest, s []byte) []byte

AppendQuoteBytesEscapeHTML behaves as AppendQuoteBytes but also escapes <, >, and &

func AppendQuoteEscapeHTML

func AppendQuoteEscapeHTML(dest []byte, s string) []byte

AppendQuoteEscapeHTML behaves as AppendQuote but also escapes <, >, and &

func IsValidNumber

func IsValidNumber(s string) bool

IsValidNumber reports whether s is a valid JSON number literal.

func IsValidNumberBytes

func IsValidNumberBytes(s []byte) bool

IsValidNumberBytes reports whether s is a valid JSON number literal.

func Unquote

func Unquote(s []byte) (t string, ok bool)

Unquote converts a quoted JSON string literal s into an actual string t. The rules are different than for Go, so cannot use strconv.Unquote.

func UnquoteBytes

func UnquoteBytes(s []byte) (t []byte, ok bool)

Types

This section is empty.

Jump to

Keyboard shortcuts

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