1 // objx - Go package for dealing with maps, slices, JSON and other data.
5 // Objx provides the `objx.Map` type, which is a `map[string]interface{}` that exposes
6 // a powerful `Get` method (among others) that allows you to easily and quickly get
7 // access to data within the map, without having to worry too much about type assertions,
8 // missing data, default values etc.
12 // Objx uses a preditable pattern to make access data from within `map[string]interface{}'s
15 // Call one of the `objx.` functions to create your `objx.Map` to get going:
17 // m, err := objx.FromJSON(json)
19 // NOTE: Any methods or functions with the `Must` prefix will panic if something goes wrong,
20 // the rest will be optimistic and try to figure things out without panicking.
22 // Use `Get` to access the value you're interested in. You can use dot and array
25 // m.Get("places[0].latlng")
27 // Once you have saught the `Value` you're interested in, you can use the `Is*` methods
28 // to determine its type.
30 // if m.Get("code").IsStr() { /* ... */ }
32 // Or you can just assume the type, and use one of the strong type methods to
33 // extract the real value:
35 // m.Get("code").Int()
37 // If there's no value there (or if it's the wrong type) then a default value
38 // will be returned, or you can be explicit about the default value.
40 // Get("code").Int(-1)
42 // If you're dealing with a slice of data as a value, Objx provides many useful
43 // methods for iterating, manipulating and selecting that data. You can find out more
44 // by exploring the index below.
48 // A simple example of how to use Objx:
50 // // use MustFromJSON to make an objx.Map from some JSON
51 // m := objx.MustFromJSON(`{"name": "Mat", "age": 30}`)
54 // name := m.Get("name").Str()
55 // age := m.Get("age").Int()
57 // // get their nickname (or use their name if they
59 // nickname := m.Get("nickname").Str(name)
63 // Since `objx.Map` is a `map[string]interface{}` you can treat it as such. For
64 // example, to `range` the data, do what you would expect:
66 // m := objx.MustFromJSON(json)
67 // for key, value := range m {
69 // /* ... do your magic ... */