Wednesday 15 June 2011

Is it possible to partially decode and update JSON? (go) -


I have to decode and update just one specific value of a JSON object. The issue is that I do not know the whole structure of the object. Encoding / JSN package "ignores" / removes not provided fields in the string so that these fields can be encoded. I am thinking that this is only the structure that I know, it is possible to update it and then martial it without reducing / removing the unknown structure / information.

It seems that this is possible. Package main import ("Encoding / Jason" "FMT" "Log") Function Main () {Type Color Structure {Space String Point Jason. RAMSase / delay parsing until we do not know the color space} Type RGB structure {RUIT 8G UIT 8B UIT 8} Type YCBCCR structure {YUIT 8 CB int 8 CR int 8} var j = [] byte (` {"Space": "YCBCR", "Point": {"Y": 255, "CB": 0, "CR": -10}} `` Mistakes in Color Colors: = json.Unmarshal (j, & If the mistake! = Zero {log. FATALLN ("error:", error)} color space = "no space" b, err: = json.marshal (and color) if mistake! = Zero {terror ( Personality)} fmt.printf ( "b is% s", b) return}


No comments:

Post a Comment