2

I need to parse arbitrary JSON structures in Golang for the sake of translating them into another language format (whether it be C structs or XML), but the Golang library apparently makes this impossible to do with Marshalling and Unmarshalling into structs and maps.

I don't necessarily even need a map-like data structure from the JSON input anyway. All I need is a recursive parser, maybe even something like PHP's XMLParser where you decide what do do yourself at each node, so I can translate it without the need for maps or interfaces.

1 Answer 1

1

There is a scanner package in the megajson package that allows you to walk through the json yourself.

scanner := scanner.NewScanner(strings.NewReader(`{"foo":"bar", 
"bat":1293,"truex":true,"falsex":false,"nullx":null,"nested":{"xxx":"yyy"}}`))

// Scan for the next JSON token.
position, token, err := scanner.Scan()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.