top

Package jsonq simplify your json usage with a simple hierarchical query.

Given some json data like:

{
	"foo": 1,
	"bar": 2,
	"test": "Hello, world!",
	"baz": 123.1,
	"array": [
		{"foo": 1},
		{"bar": 2},
		{"baz": 3}
	],
	"subobj": {
		"foo": 1,
		"subarray": [1,2,3],
		"subsubobj": {
			"bar": 2,
			"baz": 3,
			"array": ["hello", "world"]
		}
	},
	"bool": true
}

Decode it into a map[string]interrface{}:

import (
	"strings"
	"encoding/json"
	"github.com/jmoiron/jsonq"
)

data := map[string]interface{}{}
dec := json.NewDecoder(strings.NewReader(jsonstring))
dec.Decode(&data)
jq := jsonq.NewQuery(data)

From here, you can query along different keys and indexes:

// data["foo"] -> 1
jq.Int("foo")

// data["subobj"]["subarray"][1] -> 2
jq.Int("subobj", "subarray", "1")

// data["subobj"]["subarray"]["array"][0] -> "hello"
jq.String("subobj", "subsubobj", "array", "0")

// data["subobj"] -> map[string]interface{}{"subobj": ...}
obj, err := jq.Object("subobj")

Notes:

Missing keys, out of bounds indexes, and type failures will return errors. For simplicity, integer keys (ie, {"0": "zero"}) are inaccessible by `jsonq` as integer strings are assumed to be array indexes.

Imported by 95 package(s)

  1. bosun.org/cmd/bosun/sched
  2. github.com/AstromechZA/fnproject-cli
  3. github.com/CaliDog/certstream-go
  4. github.com/DudeofA/jewbot
  5. github.com/DudeofA/jewvis
  6. github.com/DudeofA/mumbledj
  7. github.com/JonathanUsername/guardian-hivemind-markov
  8. github.com/JonathanUsername/slack_markov
  9. github.com/Shadowmad/booksmart-api-server
  10. github.com/THUNDERGROOVE/census
  11. github.com/ZloyDyadka/monet/gallery
  12. github.com/aditya-dhende/cmpe273-assignment3
  13. github.com/adityabdhende/cmpe273-assignment3
  14. github.com/akoy93/hobo_signs_server
  15. github.com/ammario/mcping
  16. github.com/angdev/chocolat/api
  17. github.com/bpicolo/picfit/application
  18. github.com/buger/cloud-ssh
  19. github.com/bunyk/jsonschema2openapi
  20. github.com/chinakr/monet/gallery
  21. github.com/cleesmith/golang_learning/jsonq
  22. github.com/cleesmith/golang_learning/twitter
  23. github.com/cmacrae/xur-notify
  24. github.com/codahale/librato-collect
  25. github.com/damienstanton/gimages
  26. github.com/davemt/dumbdumb/handler
  27. github.com/figoxu/goPraticse/json/jsonq
  28. github.com/fnproject/cli/objects/app
  29. github.com/fnproject/cli/testharness
  30. github.com/fort-pinnsvin/travel/handlers
  31. github.com/gabstv/go-mgoplus
  32. github.com/gardener/gardenctl/cmd
  33. github.com/greyia/mimorin_downloader
  34. github.com/hemantasapkota/insta/commander
  35. github.com/henteko/dgate-invite/dgate
  36. github.com/heptiolabs/certstream-slack
  37. github.com/infinitbyte/framework/core/api
  38. github.com/infinitbyte/gopa/api
  39. github.com/inhies/monet/gallery
  40. github.com/invisiblethreat/certstream-go
  41. github.com/iron-io/functions/fn/commands
  42. github.com/ivangonekrazy/swirlpool
  43. github.com/jfbus/picfit/application
  44. github.com/jimmyplaza/MonitorServer
  45. github.com/jmank88/functions-1/fn
  46. github.com/jmank88/functions/fn
  47. github.com/jmoiron/monet/gallery
  48. github.com/jonog/redalert/assertions
  49. github.com/kamlendrachauhan/cmpe273-assignment2
  50. github.com/kamlendrachauhan/cmpe273-assignment3
  51. github.com/klrkdekira/j2gg
  52. github.com/luck02/dibbler/service
  53. github.com/martinpinto/functions/fn
  54. github.com/medcl/gopa/core/http
  55. github.com/medcl/gopa/modules/api/handlers
  56. github.com/medcl/gopa/modules/api/http
  57. github.com/mies/cli
  58. github.com/mixradio/klink/common
  59. github.com/mixradio/klink/exploud
  60. github.com/mixradio/klink/jenkins
  61. github.com/mixradio/klink/onix
  62. github.com/mixradio/klink/ssh
  63. github.com/mpppk/cli
  64. github.com/nsf/picfit/application
  65. github.com/ooclab/etp
  66. github.com/patrickToca/monet/gallery
  67. github.com/patrobinson/go-fish/input
  68. github.com/pedronasser/functions/fn
  69. github.com/poblahblahblah/resourced/queryparser
  70. github.com/rdallman/cli
  71. github.com/rdallman/functions/fn
  72. github.com/recordedfuture/heart_api
  73. github.com/resourced/resourced/queryparser
  74. github.com/resourced/resourced/writers
  75. github.com/reusee/FileStore/baidu
  76. github.com/rightscale/right_api_cmd
  77. github.com/saifabid/chocolat/api
  78. github.com/santanusetu/cmpe273-assignment3
  79. github.com/scusi/certstream-go
  80. github.com/sorintlab/stolon/cmd/sentinel
  81. github.com/telemetryapp/agent_crittercism/crittercism
  82. github.com/terryh/MonitorServer
  83. github.com/tirinox/go-waiter
  84. github.com/tirinox/gowaiter
  85. github.com/tonto/cli
  86. github.com/treeder/functions/fn
  87. github.com/ukd1/baremetrics-sms
  88. github.com/ulule/ipfix/application
  89. github.com/upamune/mimorin_downloader
  90. github.com/wangtuanjie/picfit/application
  91. github.com/wantedly/developers-account-mapper/services
  92. github.com/wlcx/mumbledj
  93. github.com/xwjdsh/ddns
  94. github.com/zond/diplicity/diptest
  95. github.com/zyfdegh/cadvisor/metrics

Imported only in test by 3 package(s)

  1. github.com/inteleon/logspout-redis-logstash
  2. github.com/rf-/gologs/services
  3. github.com/rtoma/logspout-redis-logstash