{"id":22682219,"url":"https://github.com/hyper-prog/smartjson","last_synced_at":"2026-04-19T02:05:08.829Z","repository":{"id":57650576,"uuid":"447939393","full_name":"hyper-prog/smartjson","owner":"hyper-prog","description":"SmartJSON - Go package to handle JSON","archived":false,"fork":false,"pushed_at":"2022-03-08T12:39:30.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T14:24:07.076Z","etag":null,"topics":["go","golang","json","json-parser","module","parser"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hyper-prog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-14T11:11:01.000Z","updated_at":"2022-02-25T15:29:50.000Z","dependencies_parsed_at":"2022-09-12T05:00:49.019Z","dependency_job_id":null,"html_url":"https://github.com/hyper-prog/smartjson","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/hyper-prog/smartjson","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper-prog%2Fsmartjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper-prog%2Fsmartjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper-prog%2Fsmartjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper-prog%2Fsmartjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyper-prog","download_url":"https://codeload.github.com/hyper-prog/smartjson/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper-prog%2Fsmartjson/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264842015,"owners_count":23671913,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","json","json-parser","module","parser"],"created_at":"2024-12-09T20:25:55.703Z","updated_at":"2026-04-19T02:05:08.790Z","avatar_url":"https://github.com/hyper-prog.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Go Reference](https://pkg.go.dev/badge/github.com/hyper-prog/smartjson.svg)](https://pkg.go.dev/github.com/hyper-prog/smartjson)\n\nSmartJSON - Go package to handle JSON\n======================================\n\nThe smartjson is a go package to handle parsed JSON files more confortable.\nThis package is not a parser. It uses the built-in \"encoding/json\" package as parser.\nIt gives you some convenient helper functions to query/view/convert parsed JSON data structures.\n\nIn order to use it you have to get the package\n\n\tgo get github.com/hyper-prog/smartjson\n\n*It seems that \"go get ...\" does not always work above go version 1.16. \nTo workaround this set the \"GO111MODULE=auto\" environment variable during go get.*\n\nCheck out the https://github.com/hyper-prog/smartyaml package to work with YAML\n\nSample code:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/hyper-prog/smartjson\"\n)\n\nvar samplejson string = `\n{\n  \"firstName\": \"John\",\n  \"lastName\": \"Smith\",\n  \"isAlive\": true,\n  \"age\": 27,\n  \"address\": {\n    \"streetAddress\": \"21 2nd Street\",\n    \"city\": \"New York\",\n    \"state\": \"NY\",\n    \"postalCode\": \"10021-3100\"\n  },\n  \"phoneNumbers\": [\n    {\n      \"type\": \"home\",\n      \"number\": \"212 555-1234\"\n    },\n    {\n      \"type\": \"office\",\n      \"number\": \"646 555-4567\"\n    }\n  ],\n  \"children\": [],\n  \"spouse\": null\n}`\n\nfunc main() {\n\t/* // Json load from file:\n\tjsonData, flerr := ioutil.ReadFile(\"test.json\")\n\tif flerr != nil {\n\t\tfmt.Println(\"Error, cannot read file: \", flerr.Error())\n\t}\n\tsj, parsererror := smartjson.ParseJSON(jsonData)\n\t*/\n\n\tsj, parsererror := smartjson.ParseJSON([]byte(samplejson))\n\tif parsererror != nil {\n\t\tfmt.Println(\"Error, not valid JSON: \", parsererror.Error())\n\t}\n\n\tfmt.Println(\"City: \", sj.GetStringByPathWithDefault(\"$.address.city\", \"Unknown\"))\n\tfmt.Println(\"First phone number: \", sj.GetStringByPathWithDefault(\"/phoneNumbers/[0]/number\", \"Not available\"))\n\t_,agetype := sj.GetNodeByPath(\"age\")\n\tfmt.Println(\"Type of Age: \", agetype)\n\t\n\tfmt.Println(\"Yaml:\")\n\tfmt.Println()\n\tfmt.Println(sj.Yaml())\n}\n```\n\nQuery path types\n----------------\n\nYou can query the nodes like directories, separated with `/` where the root sign is optional.\n\nYou can also use JsonPath to query a value.\nJsonPath mode is automatic if the query string starts with \"$.\" or \"JsonPath:\" prefix\n\n\t/members/[0]/name - Name of the first member\n\t$.members[2]/name - Name of the third member\n\t/config/items/[]/description  - The description of the last config item\n\t$.config.server.address - The address of the configured server\n\nAvailable functions\n-------------------\n\n\n| Function                                         | Description                                 |\n| ------------------------------------------------ | ------------------------------------------- |\n| `ParseJSON(rawdata []byte)`                      | Parse the JSON data                         |\n| `Yaml()`                                         | Generates a YAML string                     |\n| `JsonIndented()`                                 | Generates an indented JSON string           |\n| `JsonCompacted()`                                | Generates a compacted JSON string           |\n| `NodeExists(path string)`                        | True if the given node exists               |\n| `GetCountDescendantsByPath(path string)`         | Gives the number of descendants of the node |\n| `GetNodeByPath(path string)`                     | Gives the node and node type by path        |\n| `GetStringByPath(path string)`                   | String value of the requested node          |\n| `GetNumberByPath(path string)`                   | Float or int value as float of the requested node  |\n| `GetFloat64ByPath(path string)`                  | Float value of the requested node           |\n| `GetIntegerByPath(path string)`                  | Integer value of the requested node         |\n| `GetTimeByPath(path string)`                     | Time value of the requested node            |\n| `GetBoolByPath(path string)`                     | Bool value of the requested node            |\n| `GetStringByPathWithDefault(path string, def string)`   | String value of the requested node with fallback value  |\n| `GetNumberByPathWithDefault(path string, def float64)`  | Float or int value as float of the requested node with fallback value |\n| `GetFloat64ByPathWithDefault(path string, def float64)` | Float value of the requested node with fallback value   |\n| `GetIntegerByPathWithDefault(path string, def int)`     | Integer value of the requested node with fallback value |\n| `GetTimeByPathWithDefault(path string, def time.Time)`  | Time value of the requested node with fallback value    |\n| `GetBoolByPathWithDefault(path string, def bool)`       | Bool value of the requested node with fallback value    |\n| `GetMapByPath(path string)`                      | The map on the path                         |\n| `GetArrayByPath(path string)`                    | The array on the path                       |\n| `GetSubjsonByPath(path string)`                  | Gives the sub json specified by path        |\n\n\nAuthor, License\n---------------\n\nThe package is written by Peter Deak (C) hyper80@gmail.com under Apache 2.0 license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyper-prog%2Fsmartjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyper-prog%2Fsmartjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyper-prog%2Fsmartjson/lists"}