I can create this data structure in Python really easily:
data = {'Locations': [],
'Dates': [],
'Properties': [{'key': 'data1', 'value': 'data2'}],
'Category': 'all'}
Which can then be marshalled to JSON in Python just as easily. e.g.
print json.dumps(data)
{"Category": "all", "Dates": [], "Locations": [], "Properties": [{"value": "data2", "key": "data1"}]}
However, I'm tearing my hair out trying to create the same structure then convert it to JSON in Go. Go looks to be very promising and just what I need for creating cross platform applications, but boy this stuff seems to be frustratingly difficult.
This is what I've tried, however I cant get the structure to include the square brackets that should surround the properties element.
import (
"fmt"
"encoding/json"
)
func main() {
data := map[string]interface{}{"Offset": "0", "Properties": map[string]string{"value": "data2", "key": "data1"}, "Category": "all", "Locations": []string{}, "Dates": []string{} }
data_json, _ := json.Marshal(data)
fmt.Println(string(data_json))
}
Which outputs:
{"Category":"all","Dates":[],"Locations":[],"Offset":"0","Properties":{"key":"data1","value":"data2"}}
Heres a demo: http://play.golang.org/p/49Kytg6v_C