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