2019-08-01 11:25
浏览 107


I have a varying JSON schema (json.RawMessage) that can have an arbitrary format. I do not know the format at compile time.

In golang, I would like to check if in the root-JSON object a key exists and if so remove that key completely and deserialize.

So for example, say I need to remove "foo" if it exists

{ "foo": [1,2,3], "bar123":"baz"} -> {"bar123":"baz" }
{ "foo": "test", "bar123":"baz"} -> { "bar123":"baz" } 
{ "foo": {"bar":"bar2"}, "bar123":"baz"} -> { "bar123":"baz" }
{ "bar123":"baz"} -> { "bar123":"baz" }
{ "foo": {"bar":"bar2"}} -> {}

Given that I need to know the structure of the JSON in advance for serializing and deserializing, how can I do this with go?

1条回答 默认 最新

相关推荐 更多相似问题