Finally! I completed the full specification of what i were looking for!!
https://play.golang.org/p/eN4-FjaQS97
package main
import (
"encoding/json"
"fmt"
)
func main() {
b := []byte(`
{
"iw":{"Ie":{"Itye":{"e":"eIe"}}},
"InnerJSON2":"NoneValue",
"outterJSON":{
"innerJSON1":{
"value1":10,
"value2":22
,
"InnerInnerArray": [ "test1" , "test2"],
"InnerInnerJSONArray": [ {"fld1" : "val1"} , {"fld2" : "val2"} ]
},
"InnerJSON2":"NoneValue"
}
}
`)
f := map[string]interface{}{}
if err := json.Unmarshal(b, &f); err != nil {
panic(err)
}
verifyJSON(f)
data, _ := json.MarshalIndent(f, "", " ")
fmt.Println(string(data))
}
func verifyJSON(bv interface{}) {
var dumpJSON func(v interface{}, kn string)
dumpJSON = func(v interface{}, kn string) {
iterMap := func(x map[string]interface{}, root string) {
var knf string
if root == "root" {
knf = "%v/%v"
} else {
knf = "%v/%v"
}
for k, v := range x {
switch vv := v.(type) {
case map[string]interface{}:
fmt.Printf("%s => (map[string]interface{}) ...
", fmt.Sprintf(knf, root, k))
case []interface{}:
fmt.Printf("%s => ([]interface{}) ...
", fmt.Sprintf(knf, root, k))
default:
fmt.Printf("%s => %v
", fmt.Sprintf(knf, root, k), vv)
x[k] = "rgk"
}
dumpJSON(v, fmt.Sprintf(knf, root, k))
}
}
iterSlice := func(x []interface{}, root string) {
var knf string
if root == "root" {
knf = "%v/%v"
} else {
knf = "%v/%v"
}
for k, v := range x {
switch vv := v.(type) {
case map[string]interface{}:
fmt.Printf("%s => (map[string]interface{}) ...
", fmt.Sprintf(knf, root, k))
case []interface{}:
fmt.Printf("%s => ([]interface{}) ...
", fmt.Sprintf(knf, root, k))
default:
fmt.Printf("%s => %v
", fmt.Sprintf(knf, root, k), vv)
x[k] = "rg"
}
dumpJSON(v, fmt.Sprintf(knf, root, k))
}
}
switch vv := v.(type) {
case map[string]interface{}:
iterMap(vv, kn)
case []interface{}:
iterSlice(vv, kn)
default:
}
}
dumpJSON(bv, "root")
}