Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BreakupArray ¶
func BreakupArray(input string) []interface{}
func GetInt ¶
Example ¶
testBytes := []byte(`{"Everything":"Awesome","Team":{"Everything":"Cool", "Solution": 63}}`) var testData interface{} err := json.Unmarshal(testBytes, &testData) if err != nil { fmt.Printf("hit a snag unmarshalling the data - %v", err) } item, err := GetInt(testData, []interface{}{"Team", "Solution"}) if err != nil { fmt.Printf("hit a snag retrieving the item - %v", err) return } fmt.Println(item) fmt.Println(reflect.TypeOf(item))
Output: 63 int
func GetItem ¶
func GetItem(data interface{}, target []interface{}) (interface{}, error)
Example ¶
testBytes := []byte(`{"Everything":"Awesome","Team":{"Everything":"Cool"}}`) var testData interface{} err := json.Unmarshal(testBytes, &testData) if err != nil { fmt.Printf("hit a snag unmarshalling the data - %v", err) } item, err := GetItem(testData, []interface{}{"Team", "Everything"}) if err != nil { fmt.Printf("hit a snag retrieving the item - %v", err) } fmt.Println(item)
Output: Cool
func SetItem ¶
func SetItem(data interface{}, t []interface{}, val interface{}) (err error)
Example ¶
var err error testData := []byte(` { "field1": { "field1.1": "novalue", "field1.2": { "field1.2.1": 1, "field1.2.2": "something" } }, "field2": [[1,2],[3,4,5]] } `) res := make(map[string]interface{}) if err := json.Unmarshal(testData, &res); err != nil { fmt.Fprintln(os.Stderr, "can't unmarshal json:", err) os.Exit(1) } testData, err = json.Marshal(res) fmt.Println(string(testData)) if err := SetItem(res, []interface{}{"field1", "field1.1"}, "hello world"); err != nil { fmt.Fprintln(os.Stderr, "error:", err) } if err := SetItem(res, []interface{}{"field1", "field1.2", "field1.2.1"}, 2); err != nil { fmt.Fprintln(os.Stderr, "error:", err) } if err := SetItem(res, []interface{}{"field1", "field1.2", "field1.2.2"}, 3.14); err != nil { fmt.Fprintln(os.Stderr, "error:", err) } if err := SetItem(res, []interface{}{"field2", 0, 1}, 0xbeef); err != nil { fmt.Fprintln(os.Stderr, "error:", err) } if err := SetItem(res, []interface{}{"field2", 1}, 12345); err != nil { fmt.Fprintln(os.Stderr, "error:", err) } if testData, err = json.Marshal(res); err != nil { fmt.Fprintln(os.Stderr, "error:", err) } fmt.Println(string(testData))
Output: {"field1":{"field1.1":"novalue","field1.2":{"field1.2.1":1,"field1.2.2":"something"}},"field2":[[1,2],[3,4,5]]} {"field1":{"field1.1":"hello world","field1.2":{"field1.2.1":2,"field1.2.2":3.14}},"field2":[[1,48879],12345]}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.