{"id":43247838,"url":"https://github.com/tamboto2000/jsonextract","last_synced_at":"2026-02-01T12:47:40.692Z","repository":{"id":57558110,"uuid":"320908501","full_name":"tamboto2000/jsonextract","owner":"tamboto2000","description":"JSONExtract is a library for extracting any valid JSON from a given source, like string, bytes, file, or an io.Reader","archived":false,"fork":false,"pushed_at":"2021-02-23T17:50:50.000Z","size":5157,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-19T05:43:27.058Z","etag":null,"topics":["json-extractor","json-parsing","jsons"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tamboto2000.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":"2020-12-12T19:32:47.000Z","updated_at":"2024-06-19T05:43:27.059Z","dependencies_parsed_at":"2022-08-28T09:30:43.016Z","dependency_job_id":null,"html_url":"https://github.com/tamboto2000/jsonextract","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/tamboto2000/jsonextract","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamboto2000%2Fjsonextract","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamboto2000%2Fjsonextract/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamboto2000%2Fjsonextract/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamboto2000%2Fjsonextract/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tamboto2000","download_url":"https://codeload.github.com/tamboto2000/jsonextract/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamboto2000%2Fjsonextract/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28978313,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T12:13:08.691Z","status":"ssl_error","status_checked_at":"2026-02-01T12:13:08.356Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["json-extractor","json-parsing","jsons"],"created_at":"2026-02-01T12:47:39.435Z","updated_at":"2026-02-01T12:47:40.686Z","avatar_url":"https://github.com/tamboto2000.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSONExtract\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/tamboto2000/jsonextract.svg)](https://pkg.go.dev/github.com/tamboto2000/jsonextract/v3)\n\nPackage jsonextract is a library for extracting JSON from a given source, such as string, bytes, file, and io.Reader, providing methods for editing and evaluating json values. One of the cases to use this library is to extract all json strings in a scraped HTML page\n\n### Installation\nJSONExtract require Go v1.14 or higher\n\n```sh\n$ GO111MODULE go get github.com/tamboto2000/jsonextract/v3\n```\n\n### Sources\n\nYou can extract jsons from string, []byte, file, and an io.Reader\n\n```go\n// from string\njsons, err := jsonextract.FromString(str)\n\n// from []byte\njsons, err := jsonextract.FromBytes(byts)\n\n// from file path\njsons, err := jsonextract.FromFile(path)\n\n// from io.Reader\njsons, err := jsonextract.FromReader(reader)\n```\n\n### JSON Kinds\n\nThere's 7 different kinds of JSON:\n - Object\n - Array\n - String\n - Integer\n - Float\n - Boolean\n - Null\n\nYou can get JSON kind by calling ```JSON.Kind()```\n\n```go\njsons, err := jsonextract.FromBytes(byts)\nif err != nil {\n    panic(err.Error())\n}\n\nfor _, json := range jsons {\n    // string\n    if json.Kind() == jsonextract.String {\n        // print string value\n        fmt.Println(json.String())\n    }\n    \n    // int\n    if json.Kind() == jsonextract.Integer {\n        // print integer value, returned integer value is int64\n        fmt.Println(json.Integer())\n    }\n    \n    // float\n    if json.Kind() == jsonextract.Float {\n        // print float value, returned float is float64\n        fmt.Println(json.Float())\n    }\n    \n    // and so on...\n}\n```\n\nGetter methods, such as ```JSON.String()```, ```JSON.Integer()```, ```JSON.Float()```, etc., will panic if ```JSON``` kind did not match the getter methods, for example, when trying to get string value from ```JSON``` with kind of ```Integer```. ```JSON``` with kind of ```Null``` didn't have getter method\n\n### Modifying Value\n\nValue inside JSON can be modified by setter methods, such as ```JSON.SetStr()```, ```JSON.SetInt()```, etc.\n\n```go\n// integer\nif json.Kind() == jsonextract.Integer {\n    json.EditInt(23)\n}\n\n// string\nif json.Kind() == jsonextract.String {\n    json.EditStr(\"Hello World!\")\n}\n\n// and so on...\n```\n\nSetter methods will panic if JSON kind did not match with setter method, for example, trying to call ```JSON.SetInt()``` to ```JSON``` with kind of ```String```. ```JSON``` with kind of ```Null``` didn't have setter method\n\n### JSON Object\n\nJson object represented as ```JSON``` with kind of ```Object```. For adding a new value, call ```JSON.AddField()``` with param ```key``` as json field name, and ```val``` for the value\n\n```go\njson.AddField(\"name\", \"Franklin Collin Tamboto\")\n\njson.AddField(\"email\", \"tamboto2000@gmail.com\")\n\njson.AddField(\"id\", 1)\n\ni := 1\njson.AddField(\"id\", \u0026i)\n\n\njson.AddField(\"qty\", int32(23))\n\n\njson.AddField(\"userId\", uint(2))\n\n\njson.AddField(\"height\", float32(3.2))\n```\n\nJust like package ```encoding/json```, ```map``` and ```struct``` will be marshaled as json object. ```map``` keys need to be type ```string``` or an integer type, otherwise panic will occur\n\n```go\ntype User struct {\n    ID int `json:\"id\"`\n    Name string `json:\"name\"`\n    // field name will be used as json field name if json tag is not present, \n    // so this field will be marshaled as \"Email\":\"value\"\n    Email string\n}\n\n// add struct\njson.AddField(\"user\", User{\n    ID: 1,\n    Name: \"Franklin Collin Tamboto\",\n    Email: \"tamboto2000@gmail.com\",\n})\n\n// add map\njson.AddField(\"item\", map[interface{}]interface{}{\n    \"Name\": \"ROG Zephyrus M\",\n    \"Qty\": 23,\n    123: 456,\n})\n\n// add value with int as key\njson.AddField(123, 456)\n\n// add value with uint8 as key\njson.AddField(uint8(432), \"123\")\n```\n\nTo delete an item from object, call ```JSON.DeleteField()``` with param ```key``` as json field name for deletion. ```key``` must be string or an integer type, otherwise panic will occur. ```JSON.DeleteField()``` return ```true``` if item is exist, otherwise ```false``` will returned\n\n```go\n// delete with string key\nif json.DeleteField(\"user\") {\n    fmt.Println(\"item deleted\")\n} else {\n    fmt.Println(\"item not exist\")\n}\n\n// delete with integer key\nif json.DeleteField(int32(123)) {\n    fmt.Println(\"item deleted\")\n} else {\n    fmt.Println(\"item not exist\")\n}\n```\n\nTo access all contained items, call ```JSON.Object()```, this method will return ```map[interface{}]*JSON```\n\n```go\nfields := json.Object()\nfor _, f := range fields  {\n    // do something...\n}\n```\n\nGet contained items count by calling ```JSON.Len()```\n\n```go\nfmt.Println(\"len:\", json.Len())\n```\n\n### JSON Array\n\nJson array represented as ```JSON``` with kind of ```Array```. For adding a new value, call ```JSON.AddItem()``` with param ```val```. Will panic if ```val``` is not valid json value\n\n```go\njson.AddItem(\"Hello world\")\n```\n\nGet contained items count by calling ```JSON.Len()```\n\n```go\nfmt.Println(\"len:\", json.Len())\n```\n\nTo delete an item, call ```json.DeleteItem()``` with param ```i``` as array index\n\n```go\nif json.DeleteItem(2) {\n    fmt.Println(\"item deleted\")\n} else {\n    fmt.Println(\"item is not exist\")\n}\n```\n\nGet all items by calling ```JSON.Array()```\n\n```go\nitems := json.Array()\nfor _, item := range items {\n    // do something\n}\n```\n\n### Additional Note\nWhen an item is edited inside ```JSON```, the contained raw json will automatically re-generated.\n*DO NOT PERFORM ANY SETTER OR GETTER METHODS CONCURRENTLY*\n\n### Documentation and Examples\nSee [Documentation](https://pkg.go.dev/github.com/tamboto2000/jsonextract/v3) for more information. There's also some [examples](https://github.com/tamboto2000/jsonextract/tree/v3/examples) you can look up to \n\nLicense\n----\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftamboto2000%2Fjsonextract","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftamboto2000%2Fjsonextract","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftamboto2000%2Fjsonextract/lists"}