Friday, 20 November 2015

XML : Unmarshalling arbitrary JSON tags in Golang equivalent of XML approach?

I need to find a way to marshal/unmarshal objects in Go/JSON such that some of the tags may be arbitrary ordered, repeated, and/or not be there.

The following is an example JSON object:

  serveraddr: 172.0.0.1  narrowing:     prefix: /foo    remove-right: read    expire: 2007-01-01    label: Alice    consistency: strong  fingerprint: 0x445566       

While serveraddr, narrowing, and fingerprint all have to be there, prefix / remove / expire / label / consistency may be repeated and in an arbitrary order. The order is important.

I've coded an equivalent version w/ XML using xml.Name (Go Playground) , but I'd prefer JSON.

Ideally the marshalled output is the same as the original.

No comments:

Post a Comment