Go Library v4.23.0 released

The new version 4.23.0 contains two major changes. First is the new package gjp, an acronym for Generic JSON Parser. Reason for it is the fact, that sometimes JSON documents aren’t very good representable by nested Go structures. Here Go allows to parse documents into empty interfaces. But these are inconvenient to handle too. The GJP encapsulates this way of parsing and provides access by pathes.

Think of the following document parsed with myDoc, err := gjp.Parse(input).

{
    "foo": [
        {
            "a": true,
            "b": "hello"
        },
        {
            "a": false,
            "b": "world"
        }
    ],
    "bar": {
        "yadda": 1234
    }
}

Here e.g. myDoc.ValueAt("/foo/0/a") returns an instance of the type Value which then can be asked for the boolean value with AsBool(true). Here the true is the default value if the path points to a non-existent value. Other pathes could be "/foo/1/b" or "/bar/yadda". Value provides methods for returning the content as string, int, float64, and bool as well as IsUndefined() bool and Equals(to Value) bool.

Additionally the GJP allows to create a Diff between two documents.

Another extension is inside the stringex package. Here the new interface Processor defines a way to process strings. Several factory functions create individual processors for chaning, conditional processing, and looping as well as some other useful first processors.

More about the project at PROJECTS → Go Library.

comments powered by Disqus