go-libucl icon indicating copy to clipboard operation
go-libucl copied to clipboard

Unexpected Array Wrapping

Open zblach opened this issue 8 years ago • 0 comments

I'm not sure if this is a bug in this or libucl proper, but there seems to be some inconsistency when it comes to serialization and deserialization of maps.

ex := `name: example
rank: 5
cereal: {
  "frosted flakes" {
  	good: true
  }
  "capn crunch" {
  	good: true
  }
  "special K" {
  	good: false
  }
}`

var uclconf, jsonconf map[string]interface{}
obj, _ := ucl.ParseString(ex)
obj.Decode(&uclconf)

js, _ := obj.Emit(ucl.EmitJSONCompact) // or EmitJSON
json.Unmarshal([]byte(js), &jsonconf)

uclcereal := uclconf["cereal"].([]map[string]interface{})[0]
jsoncereal := jsonconf["cereal"].(map[string]interface{})

fmt.Println(uclcereal)
fmt.Println(jsoncereal)

output:

map[special K:[map[good:false]] frosted flakes:[map[good:true]] capn crunch:[map[good:true]]]
map[frosted flakes:map[good:true] capn crunch:map[good:true] special K:map[good:false]]

zblach avatar Aug 01 '17 01:08 zblach