[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-4883":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":22,"archived":23,"fork":23,"defaultBranch":24,"hasWiki":23,"hasPages":23,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":29,"readmeContent":30,"aiSummary":31,"trendingCount":16,"starSnapshotCount":16,"syncStatus":32,"lastSyncTime":33,"discoverSource":34},4883,"gjson","tidwall\u002Fgjson","tidwall","Get JSON values quickly - JSON parser for Go","",null,"Go",15519,900,157,96,0,1,11,41,5,80.46,"MIT License",false,"master",[26,27,28],"golang","json","json-parser","2026-06-12 04:00:23","\u003Cp align=\"center\">\n\u003Cpicture>\n  \u003Csource media=\"(prefers-color-scheme: dark)\" srcset=\"\u002F.github\u002Fimages\u002Flogo-dark.png\">\n  \u003Csource media=\"(prefers-color-scheme: light)\" srcset=\"\u002F.github\u002Fimages\u002Flogo-light.png\">\n  \u003Cimg src=\"\u002F.github\u002Fimages\u002Flogo-light.png\" width=\"240\" alt=\"GJSON\" >\n\u003C\u002Fpicture>\n\u003Cbr>\n\u003Ca href=\"https:\u002F\u002Fgodoc.org\u002Fgithub.com\u002Ftidwall\u002Fgjson\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fapi-reference-blue.svg?style=flat-square\" alt=\"GoDoc\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Ftidwall.com\u002Fgjson-play\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002F%F0%9F%8F%90-playground-9900cc.svg?style=flat-square\" alt=\"GJSON Playground\">\u003C\u002Fa>\n\u003Ca href=\"SYNTAX.md\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002F{}-syntax-33aa33.svg?style=flat-square\" alt=\"GJSON Syntax\">\u003C\u002Fa>\n\t\n\u003C\u002Fp>\n\n\u003Cp align=\"center\">get json values quickly\u003C\u002Fa>\u003C\u002Fp>\n\nGJSON is a Go package that provides a [fast](#performance) and [simple](#get-a-value) way to get values from a json document.\nIt has features such as [one line retrieval](#get-a-value), [dot notation paths](#path-syntax), [iteration](#iterate-through-an-object-or-array), and [parsing json lines](#json-lines).\n\nAlso check out [SJSON](https:\u002F\u002Fgithub.com\u002Ftidwall\u002Fsjson) for modifying json, and the [JJ](https:\u002F\u002Fgithub.com\u002Ftidwall\u002Fjj) command line tool.\n\nThis README is a quick overview of how to use GJSON, for more information check out [GJSON Syntax](SYNTAX.md).\n\nGJSON is also available for [Python](https:\u002F\u002Fgithub.com\u002Fvolans-\u002Fgjson-py) and [Rust](https:\u002F\u002Fgithub.com\u002Ftidwall\u002Fgjson.rs)\n\nGetting Started\n===============\n\n## Installing\n\nTo start using GJSON, install Go and run `go get`:\n\n```sh\n$ go get -u github.com\u002Ftidwall\u002Fgjson\n```\n\nThis will retrieve the library.\n\n## Get a value\nGet searches json for the specified path. A path is in dot syntax, such as \"name.last\" or \"age\". When the value is found it's returned immediately. \n\n```go\npackage main\n\nimport \"github.com\u002Ftidwall\u002Fgjson\"\n\nconst json = `{\"name\":{\"first\":\"Janet\",\"last\":\"Prichard\"},\"age\":47}`\n\nfunc main() {\n\tvalue := gjson.Get(json, \"name.last\")\n\tprintln(value.String())\n}\n```\n\nThis will print:\n\n```\nPrichard\n```\n*There's also [GetBytes](#working-with-bytes) for working with JSON byte slices.*\n\n## Path Syntax\n\nBelow is a quick overview of the path syntax, for more complete information please\ncheck out [GJSON Syntax](SYNTAX.md).\n\nA path is a series of keys separated by a dot.\nA key may contain special wildcard characters '\\*' and '?'.\nTo access an array value use the index as the key.\nTo get the number of elements in an array or to access a child path, use the '#' character.\nThe dot and wildcard characters can be escaped with '\\\\'.\n\n```json\n{\n  \"name\": {\"first\": \"Tom\", \"last\": \"Anderson\"},\n  \"age\":37,\n  \"children\": [\"Sara\",\"Alex\",\"Jack\"],\n  \"fav.movie\": \"Deer Hunter\",\n  \"friends\": [\n    {\"first\": \"Dale\", \"last\": \"Murphy\", \"age\": 44, \"nets\": [\"ig\", \"fb\", \"tw\"]},\n    {\"first\": \"Roger\", \"last\": \"Craig\", \"age\": 68, \"nets\": [\"fb\", \"tw\"]},\n    {\"first\": \"Jane\", \"last\": \"Murphy\", \"age\": 47, \"nets\": [\"ig\", \"tw\"]}\n  ]\n}\n```\n```\n\"name.last\"          >> \"Anderson\"\n\"age\"                >> 37\n\"children\"           >> [\"Sara\",\"Alex\",\"Jack\"]\n\"children.#\"         >> 3\n\"children.1\"         >> \"Alex\"\n\"child*.2\"           >> \"Jack\"\n\"c?ildren.0\"         >> \"Sara\"\n\"fav\\.movie\"         >> \"Deer Hunter\"\n\"friends.#.first\"    >> [\"Dale\",\"Roger\",\"Jane\"]\n\"friends.1.last\"     >> \"Craig\"\n```\n\nYou can also query an array for the first match by using `#(...)`, or find all \nmatches with `#(...)#`. Queries support the `==`, `!=`, `\u003C`, `\u003C=`, `>`, `>=` \ncomparison operators and the simple pattern matching `%` (like) and `!%` \n(not like) operators.\n\n```\nfriends.#(last==\"Murphy\").first    >> \"Dale\"\nfriends.#(last==\"Murphy\")#.first   >> [\"Dale\",\"Jane\"]\nfriends.#(age>45)#.last            >> [\"Craig\",\"Murphy\"]\nfriends.#(first%\"D*\").last         >> \"Murphy\"\nfriends.#(first!%\"D*\").last        >> \"Craig\"\nfriends.#(nets.#(==\"fb\"))#.first   >> [\"Dale\",\"Roger\"]\n```\n\n*Please note that prior to v1.3.0, queries used the `#[...]` brackets. This was\nchanged in v1.3.0 as to avoid confusion with the new\n[multipath](SYNTAX.md#multipaths) syntax. For backwards compatibility, \n`#[...]` will continue to work until the next major release.*\n\n## Result Type\n\nGJSON supports the json types `string`, `number`, `bool`, and `null`. \nArrays and Objects are returned as their raw json types. \n\nThe `Result` type holds one of these:\n\n```\nbool, for JSON booleans\nfloat64, for JSON numbers\nstring, for JSON string literals\nnil, for JSON null\n```\n\nTo directly access the value:\n\n```go\nresult.Type           \u002F\u002F can be String, Number, True, False, Null, or JSON\nresult.Str            \u002F\u002F holds the string\nresult.Num            \u002F\u002F holds the float64 number\nresult.Raw            \u002F\u002F holds the raw json\nresult.Index          \u002F\u002F index of raw value in original json, zero means index unknown\nresult.Indexes        \u002F\u002F indexes of all the elements that match on a path containing the '#' query character.\n```\n\nThere are a variety of handy functions that work on a result:\n\n```go\nresult.Exists() bool\nresult.Value() interface{}\nresult.Int() int64\nresult.Uint() uint64\nresult.Float() float64\nresult.String() string\nresult.Bool() bool\nresult.Time() time.Time\nresult.Array() []gjson.Result\nresult.Map() map[string]gjson.Result\nresult.Get(path string) Result\nresult.ForEach(iterator func(key, value Result) bool)\nresult.Less(token Result, caseSensitive bool) bool\n```\n\nThe `result.Value()` function returns an `interface{}` which requires type assertion and is one of the following Go types:\n\n```go\nboolean >> bool\nnumber  >> float64\nstring  >> string\nnull    >> nil\narray   >> []interface{}\nobject  >> map[string]interface{}\n```\n\nThe `result.Array()` function returns back an array of values.\nIf the result represents a non-existent value, then an empty array will be returned.\nIf the result is not a JSON array, the return value will be an array containing one result.\n\n### 64-bit integers\n\nThe `result.Int()` and `result.Uint()` calls are capable of reading all 64 bits, allowing for large JSON integers.\n\n```go\nresult.Int() int64    \u002F\u002F -9223372036854775808 to 9223372036854775807\nresult.Uint() uint64   \u002F\u002F 0 to 18446744073709551615\n```\n\n## Modifiers and path chaining \n\nNew in version 1.2 is support for modifier functions and path chaining.\n\nA modifier is a path component that performs custom processing on the \njson.\n\nMultiple paths can be \"chained\" together using the pipe character. \nThis is useful for getting results from a modified query.\n\nFor example, using the built-in `@reverse` modifier on the above json document,\nwe'll get `children` array and reverse the order:\n\n```\n\"children|@reverse\"           >> [\"Jack\",\"Alex\",\"Sara\"]\n\"children|@reverse|0\"         >> \"Jack\"\n```\n\nThere are currently the following built-in modifiers:\n\n- `@reverse`: Reverse an array or the members of an object.\n- `@ugly`: Remove all whitespace from a json document.\n- `@pretty`: Make the json document more human readable.\n- `@this`: Returns the current element. It can be used to retrieve the root element.\n- `@valid`: Ensure the json document is valid.\n- `@flatten`: Flattens an array.\n- `@join`: Joins multiple objects into a single object.\n- `@keys`: Returns an array of keys for an object.\n- `@values`: Returns an array of values for an object.\n- `@tostr`: Converts json to a string. Wraps a json string.\n- `@fromstr`: Converts a string from json. Unwraps a json string.\n- `@group`: Groups arrays of objects. See [e4fc67c](https:\u002F\u002Fgithub.com\u002Ftidwall\u002Fgjson\u002Fcommit\u002Fe4fc67c92aeebf2089fabc7872f010e340d105db).\n- `@dig`: Search for a value without providing its entire path. See [e8e87f2](https:\u002F\u002Fgithub.com\u002Ftidwall\u002Fgjson\u002Fcommit\u002Fe8e87f2a00dc41f3aba5631094e21f59a8cf8cbf).\n\n### Modifier arguments\n\nA modifier may accept an optional argument. The argument can be a valid JSON \ndocument or just characters.\n\nFor example, the `@pretty` modifier takes a json object as its argument. \n\n```\n@pretty:{\"sortKeys\":true} \n```\n\nWhich makes the json pretty and orders all of its keys.\n\n```json\n{\n  \"age\":37,\n  \"children\": [\"Sara\",\"Alex\",\"Jack\"],\n  \"fav.movie\": \"Deer Hunter\",\n  \"friends\": [\n    {\"age\": 44, \"first\": \"Dale\", \"last\": \"Murphy\"},\n    {\"age\": 68, \"first\": \"Roger\", \"last\": \"Craig\"},\n    {\"age\": 47, \"first\": \"Jane\", \"last\": \"Murphy\"}\n  ],\n  \"name\": {\"first\": \"Tom\", \"last\": \"Anderson\"}\n}\n```\n\n*The full list of `@pretty` options are `sortKeys`, `indent`, `prefix`, and `width`. \nPlease see [Pretty Options](https:\u002F\u002Fgithub.com\u002Ftidwall\u002Fpretty#customized-output) for more information.*\n\n### Custom modifiers\n\nYou can also add custom modifiers.\n\nFor example, here we create a modifier that makes the entire json document upper\nor lower case.\n\n```go\ngjson.AddModifier(\"case\", func(json, arg string) string {\n  if arg == \"upper\" {\n    return strings.ToUpper(json)\n  }\n  if arg == \"lower\" {\n    return strings.ToLower(json)\n  }\n  return json\n})\n```\n\n```\n\"children|@case:upper\"           >> [\"SARA\",\"ALEX\",\"JACK\"]\n\"children|@case:lower|@reverse\"  >> [\"jack\",\"alex\",\"sara\"]\n```\n\n## JSON Lines\n\nThere's support for [JSON Lines](http:\u002F\u002Fjsonlines.org\u002F) using the `..` prefix, which treats a multilined document as an array. \n\nFor example:\n\n```\n{\"name\": \"Gilbert\", \"age\": 61}\n{\"name\": \"Alexa\", \"age\": 34}\n{\"name\": \"May\", \"age\": 57}\n{\"name\": \"Deloise\", \"age\": 44}\n```\n\n```\n..#                   >> 4\n..1                   >> {\"name\": \"Alexa\", \"age\": 34}\n..3                   >> {\"name\": \"Deloise\", \"age\": 44}\n..#.name              >> [\"Gilbert\",\"Alexa\",\"May\",\"Deloise\"]\n..#(name=\"May\").age   >> 57\n```\n\nThe `ForEachLines` function will iterate through JSON lines.\n\n```go\ngjson.ForEachLine(json, func(line gjson.Result) bool{\n    println(line.String())\n    return true\n})\n```\n\n## Get nested array values\n\nSuppose you want all the last names from the following json:\n\n```json\n{\n  \"programmers\": [\n    {\n      \"firstName\": \"Janet\", \n      \"lastName\": \"McLaughlin\", \n    }, {\n      \"firstName\": \"Elliotte\", \n      \"lastName\": \"Hunter\", \n    }, {\n      \"firstName\": \"Jason\", \n      \"lastName\": \"Harold\", \n    }\n  ]\n}\n```\n\nYou would use the path \"programmers.#.lastName\" like such:\n\n```go\nresult := gjson.Get(json, \"programmers.#.lastName\")\nfor _, name := range result.Array() {\n\tprintln(name.String())\n}\n```\n\nYou can also query an object inside an array:\n\n```go\nname := gjson.Get(json, `programmers.#(lastName=\"Hunter\").firstName`)\nprintln(name.String())  \u002F\u002F prints \"Elliotte\"\n```\n\n## Iterate through an object or array\n\nThe `ForEach` function allows for quickly iterating through an object or array. \nThe key and value are passed to the iterator function for objects.\nOnly the value is passed for arrays.\nReturning `false` from an iterator will stop iteration.\n\n```go\nresult := gjson.Get(json, \"programmers\")\nresult.ForEach(func(key, value gjson.Result) bool {\n\tprintln(value.String()) \n\treturn true \u002F\u002F keep iterating\n})\n```\n\n## Simple Parse and Get\n\nThere's a `Parse(json)` function that will do a simple parse, and `result.Get(path)` that will search a result.\n\nFor example, all of these will return the same result:\n\n```go\ngjson.Parse(json).Get(\"name\").Get(\"last\")\ngjson.Get(json, \"name\").Get(\"last\")\ngjson.Get(json, \"name.last\")\n```\n\n## Check for the existence of a value\n\nSometimes you just want to know if a value exists. \n\n```go\nvalue := gjson.Get(json, \"name.last\")\nif !value.Exists() {\n\tprintln(\"no last name\")\n} else {\n\tprintln(value.String())\n}\n\n\u002F\u002F Or as one step\nif gjson.Get(json, \"name.last\").Exists() {\n\tprintln(\"has a last name\")\n}\n```\n\n## Validate JSON\n\nThe `Get*` and `Parse*` functions expects that the json is well-formed. Bad json will not panic, but it may return back unexpected results.\n\nIf you are consuming JSON from an unpredictable source then you may want to validate prior to using GJSON.\n\n```go\nif !gjson.Valid(json) {\n\treturn errors.New(\"invalid json\")\n}\nvalue := gjson.Get(json, \"name.last\")\n```\n\n## Unmarshal to a map\n\nTo unmarshal to a `map[string]interface{}`:\n\n```go\nm, ok := gjson.Parse(json).Value().(map[string]interface{})\nif !ok {\n\t\u002F\u002F not a map\n}\n```\n\n## Working with Bytes\n\nIf your JSON is contained in a `[]byte` slice, there's the [GetBytes](https:\u002F\u002Fgodoc.org\u002Fgithub.com\u002Ftidwall\u002Fgjson#GetBytes) function. This is preferred over `Get(string(data), path)`.\n\n```go\nvar json []byte = ...\nresult := gjson.GetBytes(json, path)\n```\n\nIf you are using the `gjson.GetBytes(json, path)` function and you want to avoid converting `result.Raw` to a `[]byte`, then you can use this pattern:\n\n```go\nvar json []byte = ...\nresult := gjson.GetBytes(json, path)\nvar raw []byte\nif result.Index > 0 {\n    raw = json[result.Index:result.Index+len(result.Raw)]\n} else {\n    raw = []byte(result.Raw)\n}\n```\n\nThis is a best-effort no allocation sub slice of the original json. This method utilizes the `result.Index` field, which is the position of the raw data in the original json. It's possible that the value of `result.Index` equals zero, in which case the `result.Raw` is converted to a `[]byte`.\n\n## Performance\n\nBenchmarks of GJSON alongside [encoding\u002Fjson](https:\u002F\u002Fgolang.org\u002Fpkg\u002Fencoding\u002Fjson\u002F), \n[ffjson](https:\u002F\u002Fgithub.com\u002Fpquerna\u002Fffjson), \n[EasyJSON](https:\u002F\u002Fgithub.com\u002Fmailru\u002Feasyjson),\n[jsonparser](https:\u002F\u002Fgithub.com\u002Fbuger\u002Fjsonparser),\nand [json-iterator](https:\u002F\u002Fgithub.com\u002Fjson-iterator\u002Fgo)\n\n```\nBenchmarkGJSONGet-10             17893731    202.1 ns\u002Fop      0 B\u002Fop     0 allocs\u002Fop\nBenchmarkGJSONUnmarshalMap-10     1663548   2157 ns\u002Fop     1920 B\u002Fop    26 allocs\u002Fop\nBenchmarkJSONUnmarshalMap-10       832236   4279 ns\u002Fop     2920 B\u002Fop    68 allocs\u002Fop\nBenchmarkJSONUnmarshalStruct-10   1076475   3219 ns\u002Fop      920 B\u002Fop    12 allocs\u002Fop\nBenchmarkJSONDecoder-10            585729   6126 ns\u002Fop     3845 B\u002Fop   160 allocs\u002Fop\nBenchmarkFFJSONLexer-10           2508573   1391 ns\u002Fop      880 B\u002Fop     8 allocs\u002Fop\nBenchmarkEasyJSONLexer-10         3000000    537.9 ns\u002Fop    501 B\u002Fop     5 allocs\u002Fop\nBenchmarkJSONParserGet-10        13707510    263.9 ns\u002Fop     21 B\u002Fop     0 allocs\u002Fop\nBenchmarkJSONIterator-10          3000000    561.2 ns\u002Fop    693 B\u002Fop    14 allocs\u002Fop\n```\n\nJSON document used:\n\n```json\n{\n  \"widget\": {\n    \"debug\": \"on\",\n    \"window\": {\n      \"title\": \"Sample Konfabulator Widget\",\n      \"name\": \"main_window\",\n      \"width\": 500,\n      \"height\": 500\n    },\n    \"image\": { \n      \"src\": \"Images\u002FSun.png\",\n      \"hOffset\": 250,\n      \"vOffset\": 250,\n      \"alignment\": \"center\"\n    },\n    \"text\": {\n      \"data\": \"Click Here\",\n      \"size\": 36,\n      \"style\": \"bold\",\n      \"vOffset\": 100,\n      \"alignment\": \"center\",\n      \"onMouseUp\": \"sun1.opacity = (sun1.opacity \u002F 100) * 90;\"\n    }\n  }\n}    \n```\n\nEach operation was rotated through one of the following search paths:\n\n```\nwidget.window.name\nwidget.image.hOffset\nwidget.text.onMouseUp\n```\n\n**\n\n*These benchmarks were run on a MacBook Pro M1 Max using Go 1.22 and can be found [here](https:\u002F\u002Fgithub.com\u002Ftidwall\u002Fgjson-benchmarks).*\n","GJSON 是一个用于快速从 JSON 文档中提取值的 Go 语言包。其核心功能包括通过简洁的一行代码检索、使用点符号路径访问数据、迭代对象或数组以及解析 JSON Lines 格式的数据，具有高性能和易用性。特别适合需要高效处理 JSON 数据的应用场景，如 Web 开发中的 API 响应解析、日志分析等。此外，GJSON 还支持 Python 和 Rust 版本，为跨语言开发提供了便利。",2,"2026-06-11 03:01:17","top_language"]