package json

import "git.sr.ht/~shulhan/pakakeh.go/lib/json"

Package json provide a library for working with JSON.

This is an extension to standard "encoding/json" package.

Index

Functions

func Escape

func Escape(in []byte) []byte

Escape the following character: `"` (quotation mark), `\` (reverse solidus), `\b` (backspace), `\f` (formfeed), `\n` (newline), `\r` (carriage return`), `\t` (horizontal tab), and control character from 0 - 31.

References:

* https://tools.ietf.org/html/rfc7159#page-8

func EscapeString

func EscapeString(in string) string

EscapeString escape the following character: `"` (quotation mark), `\` (reverse solidus), `\b` (backspace), `\f` (formfeed), `\n` (newline), `\r` (carriage return`), `\t` (horizontal tab), and control character from 0 - 31.

References

* https://tools.ietf.org/html/rfc7159#page-8

func ToMapStringFloat64

func ToMapStringFloat64(in map[string]any) (out map[string]float64, err error)

ToMapStringFloat64 convert the map of string-any into map of string-float64. This function convert the map's key to lower-cases and ignore zero value in any. The any value only accept basic numeric types and slice of byte.

func Unescape

func Unescape(in []byte, strict bool) (out []byte, err error)

Unescape JSON bytes, reversing what Escape function do.

If strict is true, any unknown control character will be returned as error. For example, in string "\x", "x" is not valid control character, and the function will return empty string and error. If strict is false, it will return "x".

func UnescapeString

func UnescapeString(in string, strict bool) (string, error)

UnescapeString unescape JSON string, reversing what EscapeString do.

If strict is true, any unknown control character will be returned as error. For example, in string "\x", "x" is not valid control character, and the function will return empty string and error. If strict is false, it will return "x".

Source Files

json.go

Version
v0.60.0 (latest)
Published
Feb 1, 2025
Platform
linux/amd64
Imports
5 packages
Last checked
25 minutes ago

Tools for package owners.