Create a Go #json #parser: Batteries Included
▻https://hackernoon.com/create-a-go-json-parser-batteries-included-9d02d09fe508?source=rss----3a
The inspiration for this post came from a project at work. I was building a service that required the comparison of two Json objects. The catch was that I needed to be able to replace keys, filter out paths, and apply comparison functions to specific nodes.Obviously, a standard library comparison function such as reflect.DeepEqual() would not work. ?The solution was to build a AST(Abstract Syntax Tree) modeled off of the Json objects. Every Node in the tree represents either a string, integer, array, or object.By doing this I would allow for the flexibility to more easily apply algorithms onto the data.To build this we’ll start with the Lexer to generate Tokens. Then move onto the Parser which will take the tokens and match them to Json grammar. Finally, we’ll add AST hooks to generate the (...)