top

objx - Go package for dealing with maps, slices, JSON and other data.

Overview

Objx provides the `objx.Map` type, which is a `map[string]interface{}` that exposes a powerful `Get` method (among others) that allows you to easily and quickly get access to data within the map, without having to worry too much about type assertions, missing data, default values etc.

Pattern

Objx uses a preditable pattern to make access data from within `map[string]interface{}'s easy.

Call one of the `objx.` functions to create your `objx.Map` to get going:

m, err := objx.FromJSON(json)

NOTE: Any methods or functions with the `Must` prefix will panic if something goes wrong, the rest will be optimistic and try to figure things out without panicking.

Use `Get` to access the value you're interested in. You can use dot and array notation too:

m.Get("places[0].latlng")

Once you have saught the `Value` you're interested in, you can use the `Is*` methods to determine its type.

if m.Get("code").IsStr() { /* ... */ }

Or you can just assume the type, and use one of the strong type methods to extract the real value:

m.Get("code").Int()

If there's no value there (or if it's the wrong type) then a default value will be returned, or you can be explicit about the default value.

Get("code").Int(-1)

If you're dealing with a slice of data as a value, Objx provides many useful methods for iterating, manipulating and selecting that data. You can find out more by exploring the index below.

Reading data

A simple example of how to use Objx:

// use MustFromJSON to make an objx.Map from some JSON
m := objx.MustFromJSON(`{"name": "Mat", "age": 30}`)

// get the details
name := m.Get("name").Str()
age := m.Get("age").Int()

// get their nickname (or use their name if they
// don't have one)
nickname := m.Get("nickname").Str(name)

Ranging

Since `objx.Map` is a `map[string]interface{}` you can treat it as such. For example, to `range` the data, do what you would expect:

m := objx.MustFromJSON(json)
for key, value := range m {

  /* ... do your magic ... */

}

Imported by 326 package(s)

  1. github.com/89hmdys/testify/mock
  2. github.com/ANPez/testify/mock
  3. github.com/AndyHaskell/testify/mock
  4. github.com/Billups/testify/mock
  5. github.com/C2FO/testify/mock
  6. github.com/Fiery/testify/mock
  7. github.com/G-pu/testify/mock
  8. github.com/HawaiianSpork/testify/mock
  9. github.com/IsaacRoss/go-chat
  10. github.com/MicrosmartSA/testify/mock
  11. github.com/MindFlavor/goimgshare
  12. github.com/Monnoroch/testify/mock
  13. github.com/NikitaSmall/gochat
  14. github.com/R1mbo/chat
  15. github.com/Radiobox/codecs
  16. github.com/Radiobox/codecs/csv
  17. github.com/Radiobox/codecs/xml
  18. github.com/Radiobox/goweb/context
  19. github.com/Radiobox/goweb/handlers
  20. github.com/Radiobox/goweb/paths
  21. github.com/Radiobox/goweb/webcontext
  22. github.com/Radiobox/osin
  23. github.com/Radiobox/rest_codecs
  24. github.com/Radiobox/rest_codecs/codecs
  25. github.com/Radiobox/web_request_readers
  26. github.com/Radiobox/web_responders
  27. github.com/Radiobox/web_responders/codecs
  28. github.com/Ripounet/goblueprints/chapter2/chat
  29. github.com/Ripounet/goblueprints/chapter3/chat
  30. github.com/TechnotronicOz/testify/mock
  31. github.com/abelfletcher/testify/mock
  32. github.com/abhasrambo/Chat
  33. github.com/ac7/testify/mock
  34. github.com/agileknight/testify/mock
  35. github.com/amencarini/gomniauth
  36. github.com/amencarini/gomniauth/common
  37. github.com/amencarini/gomniauth/oauth2
  38. github.com/amencarini/gomniauth/test
  39. github.com/andybons/testify/mock
  40. github.com/anpez/testify/mock
  41. github.com/ansel1/testify/mock
  42. github.com/anupcshan/testify/mock
  43. github.com/appcanary/testify/mock
  44. github.com/ashish173/gomniauth
  45. github.com/ashish173/gomniauth/common
  46. github.com/ashish173/gomniauth/oauth2
  47. github.com/ashish173/gomniauth/test
  48. github.com/attic-labs/testify/mock
  49. github.com/boudra/testify/mock
  50. github.com/brahmaroutu/testify/mock
  51. github.com/brildum/testify/mock
  52. github.com/c2fo/testify/mock
  53. github.com/cam72cam/testify/mock
  54. github.com/cocoonlife/testify/mock
  55. github.com/comogo/testify/mock
  56. github.com/contactless/wb-rules/wbrules
  57. github.com/contactless/wbgo/testutils
  58. github.com/coxx/testify/mock
  59. github.com/danjac/photoshare
  60. github.com/dankozitza/silverback/codecs
  61. github.com/darthlukan/AOW-Server
  62. github.com/darthlukan/cakeday
  63. github.com/darthlukan/gobit
  64. github.com/darthlukan/keeper
  65. github.com/darthlukan/liquor-dev
  66. github.com/denkhaus/crfetch
  67. github.com/dev-hartmann/testify/mock
  68. github.com/dlclark/testify/mock
  69. github.com/dmikalova/practice/programming-blueprints/chat
  70. github.com/docbobo/testify/mock
  71. github.com/dora56/chat
  72. github.com/dweinand/testify/mock
  73. github.com/dwlnetnl/testify/mock
  74. github.com/e247/gomniauth
  75. github.com/e247/gomniauth/common
  76. github.com/e247/gomniauth/example/nethttp
  77. github.com/e247/gomniauth/oauth2
  78. github.com/e247/gomniauth/providers/facebook
  79. github.com/e247/gomniauth/providers/github
  80. github.com/e247/gomniauth/providers/google
  81. github.com/e247/gomniauth/providers/heroku
  82. github.com/e247/gomniauth/providers/soundcloud
  83. github.com/e247/gomniauth/test
  84. github.com/esdrasbeleza/testify/mock
  85. github.com/eyesight-tech/testify/mock
  86. github.com/forqlift/testify/mock
  87. github.com/gengo/goship/lib/auth
  88. github.com/gernest/hero/demo
  89. github.com/gernest/hero/demo/client
  90. github.com/getlantern/testify/mock
  91. github.com/go-distributed/testify/mock
  92. github.com/go-on/routergomniauth
  93. github.com/goestoeleven/goblueprints/chapter2/chat
  94. github.com/goestoeleven/goblueprints/chapter3/chat
  95. github.com/gopher2121/gocode/webapp
  96. github.com/guncha/testify/mock
  97. github.com/h4ckm03d/gomniauth
  98. github.com/h4ckm03d/gomniauth/common
  99. github.com/h4ckm03d/gomniauth/oauth2
  100. github.com/h4ckm03d/gomniauth/providers/facebook
  101. github.com/h4ckm03d/gomniauth/providers/github
  102. github.com/h4ckm03d/gomniauth/providers/google
  103. github.com/h4ckm03d/gomniauth/providers/soundcloud
  104. github.com/h4ckm03d/gomniauth/test
  105. github.com/hagna/photoshare
  106. github.com/heitorlessa/golearning/exercises/chat_websocket
  107. github.com/hhkbp2/testify/mock
  108. github.com/icecrime/testify/mock
  109. github.com/imrickrick/auth0Login/goauth2appengine
  110. github.com/insionng/vodka/libraries/stretchr/testify/mock
  111. github.com/interactiv/blueprint/chat
  112. github.com/jaguilar/testify/mock
  113. github.com/jbert/testify/mock
  114. github.com/jmcgill0brightcove/testify/mock
  115. github.com/joonazan/go-opas/palvelin
  116. github.com/joonazan/signature/siggen
  117. github.com/jteso/testify/mock
  118. github.com/jwilder/gofana
  119. github.com/jwilder/gomniauth
  120. github.com/jwilder/gomniauth/common
  121. github.com/jwilder/gomniauth/oauth2
  122. github.com/jwilder/gomniauth/test
  123. github.com/keito-jp/chat
  124. github.com/keiwt/goblueprints/chat
  125. github.com/kevensen/chat
  126. github.com/khirayama/go-training/oreilly/chat
  127. github.com/khirayama/gomniauth
  128. github.com/khirayama/gomniauth/common
  129. github.com/khirayama/gomniauth/example/nethttp
  130. github.com/khirayama/gomniauth/oauth2
  131. github.com/khirayama/gomniauth/providers/facebook
  132. github.com/khirayama/gomniauth/providers/github
  133. github.com/khirayama/gomniauth/providers/gitlab
  134. github.com/khirayama/gomniauth/providers/google
  135. github.com/khirayama/gomniauth/providers/heroku
  136. github.com/khirayama/gomniauth/providers/instagram
  137. github.com/khirayama/gomniauth/providers/soundcloud
  138. github.com/khirayama/gomniauth/providers/spotify
  139. github.com/khirayama/gomniauth/providers/uber
  140. github.com/khirayama/gomniauth/test
  141. github.com/khirayama/handle
  142. github.com/kogai/goblueprints/chapter2/chat
  143. github.com/kogai/goblueprints/chapter3/chat
  144. github.com/konami99/go/ch1
  145. github.com/kriox26/gbp-chat
  146. github.com/kriox26/goblueprints/chapter2/chat
  147. github.com/kriox26/goblueprints/chapter3/chat
  148. github.com/ktship/go_chat_app
  149. github.com/kyokomi/bouillabaisse/firebase/provider
  150. github.com/laurentlbm/goweb/context
  151. github.com/laurentlbm/goweb/handlers
  152. github.com/laurentlbm/goweb/paths
  153. github.com/laurentlbm/goweb/webcontext
  154. github.com/levilovelock/testify/mock
  155. github.com/liyu-wang/go-chat
  156. github.com/lonnc/gomniauth
  157. github.com/lonnc/gomniauth/common
  158. github.com/lonnc/gomniauth/oauth2
  159. github.com/lonnc/gomniauth/test
  160. github.com/lstern/psilibrary/server/repositories
  161. github.com/lummie/testify/mock
  162. github.com/lynndylanhurley/defsynth-api/controllers
  163. github.com/lzbgt/goweb/context
  164. github.com/lzbgt/goweb/handlers
  165. github.com/lzbgt/goweb/paths
  166. github.com/lzbgt/goweb/webcontext
  167. github.com/maraino/testify/mock
  168. github.com/marcsv/testify/mock
  169. github.com/materials-commons/testify/mock
  170. github.com/matryer/goblueprints/chapter2/chat
  171. github.com/matryer/goblueprints/chapter3/chat
  172. github.com/matryer/pangaea
  173. github.com/mcuadros/harvester/src/util
  174. github.com/mesosphere/testify/mock
  175. github.com/mhamrah/goblueprints/chapter2/chat
  176. github.com/mhamrah/goblueprints/chapter3/chat
  177. github.com/mindflavor/goimgshare
  178. github.com/mosson/chat-sample/chat-sample
  179. github.com/muesli/goblueprints/chapter2/chat
  180. github.com/muesli/goblueprints/chapter3/chat
  181. github.com/multiplay/testify/mock
  182. github.com/nelsam/web_responders
  183. github.com/nemothekid/goweb/context
  184. github.com/nemothekid/goweb/handlers
  185. github.com/nemothekid/goweb/paths
  186. github.com/nemothekid/goweb/webcontext
  187. github.com/nemowen/chat
  188. github.com/nikitasmall/gochat
  189. github.com/ntk1000/go-web-book-playground/c2
  190. github.com/nyarly/testify/mock
  191. github.com/oldenbur/goblueprints/chapter2/chat
  192. github.com/oldenbur/goblueprints/chapter3/chat
  193. github.com/onsi/testify/mock
  194. github.com/onufert/chat
  195. github.com/outdoorsy/web_responders
  196. github.com/outrightmental/go-signature/siggen
  197. github.com/outrightmental/go-testify/mock
  198. github.com/oyvindsk/go-blueprints-chat
  199. github.com/pengux/goweb/context
  200. github.com/pengux/goweb/handlers
  201. github.com/pengux/goweb/paths
  202. github.com/pengux/goweb/webcontext
  203. github.com/pirosikick/go-api-example/chat
  204. github.com/pki-io/testify/mock
  205. github.com/raphaelmeyer/testify/mock
  206. github.com/raspberrypython/testify/mock
  207. github.com/realistschuckle/testify/mock
  208. github.com/rewardStyle/testify/mock
  209. github.com/rhtps/gochat
  210. github.com/rmulley/goweb/context
  211. github.com/rmulley/goweb/paths
  212. github.com/rmulley/goweb/webcontext
  213. github.com/rusenask/chat
  214. github.com/seansu4you87/testify/mock
  215. github.com/seantalts/testify/mock
  216. github.com/sgmac/goblueprints/chat
  217. github.com/shaalx/testify/mock
  218. github.com/shicky/go-gorilla-skeleton
  219. github.com/smallsweet/gofana
  220. github.com/smyrman/testify/mock
  221. github.com/spacedock-io/index/config
  222. github.com/spacedock-io/registry/cloudfiles
  223. github.com/spacedock-io/registry/config
  224. github.com/spacedock-io/registry/db
  225. github.com/spacejam/testify/mock
  226. github.com/stretchr/codecs
  227. github.com/stretchr/codecs/csv
  228. github.com/stretchr/codecs/xml
  229. github.com/stretchr/commander
  230. github.com/stretchr/config
  231. github.com/stretchr/gomniauth
  232. github.com/stretchr/gomniauth/common
  233. github.com/stretchr/gomniauth/example/nethttp
  234. github.com/stretchr/gomniauth/oauth2
  235. github.com/stretchr/gomniauth/providers/facebook
  236. github.com/stretchr/gomniauth/providers/github
  237. github.com/stretchr/gomniauth/providers/gitlab
  238. github.com/stretchr/gomniauth/providers/google
  239. github.com/stretchr/gomniauth/providers/heroku
  240. github.com/stretchr/gomniauth/providers/instagram
  241. github.com/stretchr/gomniauth/providers/soundcloud
  242. github.com/stretchr/gomniauth/providers/spotify
  243. github.com/stretchr/gomniauth/providers/uber
  244. github.com/stretchr/gomniauth/test
  245. github.com/stretchr/gorc
  246. github.com/stretchr/goweb/context
  247. github.com/stretchr/goweb/handlers
  248. github.com/stretchr/goweb/paths
  249. github.com/stretchr/goweb/webcontext
  250. github.com/stretchr/objx/examples
  251. github.com/stretchr/pangaea
  252. github.com/stretchr/sdk-go
  253. github.com/stretchr/sdk-go/api
  254. github.com/stretchr/signature/siggen
  255. github.com/stretchr/testify/mock
  256. github.com/stretchrcom/goweb/context
  257. github.com/stretchrcom/goweb/handlers
  258. github.com/stretchrcom/goweb/paths
  259. github.com/stretchrcom/goweb/webcontext
  260. github.com/stretchrcom/testify/mock
  261. github.com/subosito/anoa/github
  262. github.com/suifengRock/testify/mock
  263. github.com/syo-sa1982/gomniauth
  264. github.com/syo-sa1982/gomniauth/common
  265. github.com/syo-sa1982/gomniauth/oauth2
  266. github.com/syo-sa1982/gomniauth/providers/facebook
  267. github.com/syo-sa1982/gomniauth/providers/github
  268. github.com/syo-sa1982/gomniauth/providers/gitlab
  269. github.com/syo-sa1982/gomniauth/providers/google
  270. github.com/syo-sa1982/gomniauth/providers/heroku
  271. github.com/syo-sa1982/gomniauth/providers/instagram
  272. github.com/syo-sa1982/gomniauth/providers/soundcloud
  273. github.com/syo-sa1982/gomniauth/providers/spotify
  274. github.com/syo-sa1982/gomniauth/providers/uber
  275. github.com/syo-sa1982/gomniauth/test
  276. github.com/syo-sa1982/gostudy/chat
  277. github.com/tchajed/testify/mock
  278. github.com/tcsc/testify/mock
  279. github.com/tgreiser/goweb/context
  280. github.com/tgreiser/goweb/handlers
  281. github.com/tgreiser/goweb/paths
  282. github.com/tgreiser/goweb/webcontext
  283. github.com/thenonameguy/gomniauth
  284. github.com/thenonameguy/gomniauth/common
  285. github.com/thenonameguy/gomniauth/oauth2
  286. github.com/thenonameguy/gomniauth/test
  287. github.com/thenonameguy/goweb/context
  288. github.com/thenonameguy/goweb/handlers
  289. github.com/thenonameguy/goweb/paths
  290. github.com/thenonameguy/goweb/webcontext
  291. github.com/tiengtinh/go-talk
  292. github.com/toggl/gomniauth
  293. github.com/toggl/gomniauth/common
  294. github.com/toggl/gomniauth/oauth2
  295. github.com/toggl/gomniauth/providers/facebook
  296. github.com/toggl/gomniauth/providers/github
  297. github.com/toggl/gomniauth/providers/gitlab
  298. github.com/toggl/gomniauth/providers/google
  299. github.com/toggl/gomniauth/providers/heroku
  300. github.com/toggl/gomniauth/providers/instagram
  301. github.com/toggl/gomniauth/providers/soundcloud
  302. github.com/toggl/gomniauth/providers/spotify
  303. github.com/toggl/gomniauth/providers/uber
  304. github.com/toggl/gomniauth/test
  305. github.com/treetopllc/gorc
  306. github.com/tylerb/web_responders
  307. github.com/ukai/go-programming-blueprints/appendixB/chat
  308. github.com/ukai/go-programming-blueprints/chapter2/chat
  309. github.com/ukai/go-programming-blueprints/chapter3/chat
  310. github.com/vfarcic/go-practice
  311. github.com/vfarcic/oauth
  312. github.com/victorkryukov/testify/mock
  313. github.com/viniciusfeitosa/chatGo
  314. github.com/wallclockbuilder/testify/mock
  315. github.com/willfaught/testify/mock
  316. github.com/willogden/testify/mock
  317. github.com/xyq946692052/testify/mock
  318. github.com/yifan-gu/testify/mock
  319. github.com/ys/deploysaurus/deploysaurus
  320. github.com/ys/deploysaurus/heroku
  321. github.com/zacg/testify/mock
  322. github.com/zonas/testify/mock
  323. gopkg.in/c2fo/testify.v1/mock
  324. gopkg.in/go-on/router.v2/third-party/routergomniauth
  325. gopkg.in/kyokomi/bouillabaisse.v0/firebase/provider
  326. gopkg.in/stretchr/testify.v1/mock

Imported only in test by 6 package(s)

  1. github.com/Radiobox/codecs/services
  2. github.com/contactless/wb-mqtt-confed/confed
  3. github.com/contactless/wbgo
  4. github.com/jamesrr39/filelint
  5. github.com/stretchr/codecs/services
  6. github.com/stretchrcom/codecs/services

Test imports 1 package(s)

  1. github.com/stretchr/testify/assert