jsoneasy
Overview
Inspired by JavaScript's JSON methods, jsoneasy
contains two methods: Stringify
and Parse
.
In addition to using these clear and well-understood names instead of
"Marshall," "Unmarshal," etc., the jsoneasy
package addresses the false
assumption that the Go's built-in encoding/json package makes: By default,
json.Marshal
converts &, <, > characters to Unicode in its generated JSON
string output. This is helpful only when in an HTML (or XML) context. Otherwise,
it is a mistake.
JSON.Stringify does not convert &, <, > to Unicode, thus preserving the
integrity of the original content.
Examples
import "codeberg.org/gold/jsoneasy"
var JSON = jsoneasy.JSON{}
func main() {
data := map[string]interface{
"dimension": "fourth",
"ThePrisonerName": 2,
"number": "e",
"isPackageUseful": true,
}
// 2nd arg is the indent level.
jsonString, err := JSON.Stringify(data, 2)
myParsedData := make(map[string](interface{}))
err := JSON.Parse(jsonString, &myParsedData)
}
Credits
Gerry Gold, June 2023
Have fun!