2021年3月16日星期二

Golang Unmarshall specific object in nested JSON

what is the best practice to unmarshall a specific part of a large JSON with static property names in GO?

my JSON map looks like

{      "top_view" : {         "@self" : "https://generic.com",             "graph" : {                "nodes" : [ { } ],                "relations" : [ { } ]                       },           "view_status" : {}                   }  }  

and I only need to retrieve the Nodes array

Here is what I got so far,

https://play.golang.org/p/btfRojEGqUu

I only know how to unmarshall the Nodes part, but I don't know how to tell Go to start unmarshalling only that object, so the code won't work if I feed the entire JSON tree. Please advise, thanks!

https://stackoverflow.com/questions/66667059/golang-unmarshall-specific-object-in-nested-json March 17, 2021 at 12:36PM

没有评论:

发表评论