{"id":32948884,"url":"https://github.com/asty-org/asty","last_synced_at":"2026-01-14T22:11:14.576Z","repository":{"id":59045122,"uuid":"527986453","full_name":"asty-org/asty","owner":"asty-org","description":"Converts golang AST to JSON and JSON to AST","archived":false,"fork":false,"pushed_at":"2023-05-22T22:53:34.000Z","size":1134,"stargazers_count":76,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-20T03:37:35.200Z","etag":null,"topics":["ast","go","golang","json","parser"],"latest_commit_sha":null,"homepage":"https://asty-org.github.io/","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/asty-org.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-08-23T12:44:01.000Z","updated_at":"2024-05-18T03:42:55.000Z","dependencies_parsed_at":"2024-01-08T16:09:05.700Z","dependency_job_id":"36bc3daa-6ca8-418e-b7b9-dd9b380a69e7","html_url":"https://github.com/asty-org/asty","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/asty-org/asty","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asty-org%2Fasty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asty-org%2Fasty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asty-org%2Fasty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asty-org%2Fasty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asty-org","download_url":"https://codeload.github.com/asty-org/asty/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asty-org%2Fasty/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28436268,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T21:32:52.117Z","status":"ssl_error","status_checked_at":"2026-01-14T21:32:33.442Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["ast","go","golang","json","parser"],"created_at":"2025-11-12T20:00:35.672Z","updated_at":"2026-01-14T22:11:14.562Z","avatar_url":"https://github.com/asty-org.png","language":"Go","funding_links":[],"categories":["Code Analysis","代码分析"],"sub_categories":["Routers","路由器"],"readme":"# asty\n\n![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/asty-org/asty)\n[![Go Reference](https://pkg.go.dev/badge/github.com/asty-org/asty.svg)](https://pkg.go.dev/github.com/asty-org/asty)\n[![Go Report Card](https://goreportcard.com/badge/github.com/asty-org/asty)](https://goreportcard.com/report/github.com/asty-org/asty)\n![Codecov](https://img.shields.io/codecov/c/github/asty-org/asty)\n[![GitHub last commit](https://img.shields.io/github/last-commit/asty-org/asty)](https://github.com/asty-org/asty)\n[![Docker Pulls](https://img.shields.io/docker/pulls/astyorg/asty)](https://hub.docker.com/r/astyorg/asty)\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go#code-analysis)\n\n_Not another JSON parser!_\n\n**AST \u0026#8594; JSON** | **JSON \u0026#8594; AST**\n\nMarshals golang [AST](https://pkg.go.dev/go/ast) into JSON and unmarshals it back from JSON.\n\nIt allows building pattern matching, statistical analysis, language transformation, search/data-mine/anything algorithms\nfor golang with any other language (I like to do it with python. Check out [asty-python](https://github.com/asty-org/asty-python))\n\n## Example\n\n[Try it!](https://asty-org.github.io/)\n\nInput golang source\n\n```golang\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(\"hello world\")\n}\n```\n\nOuput AST in JSON\n\n```json\n{\n  \"NodeType\": \"File\",\n  \"Name\": {\n    \"NodeType\": \"Ident\",\n    \"Name\": \"main\"\n  },\n  \"Decls\": [\n    {\n      \"NodeType\": \"GenDecl\",\n      \"Tok\": \"import\",\n      \"Specs\": [\n        {\n          \"NodeType\": \"ImportSpec\",\n          \"Name\": null,\n          \"Path\": {\n            \"NodeType\": \"BasicLit\",\n            \"Kind\": \"STRING\",\n            \"Value\": \"\\\"fmt\\\"\"\n          }\n        }\n      ]\n    },\n    {\n      \"NodeType\": \"FuncDecl\",\n      \"Recv\": null,\n      \"Name\": {\n        \"NodeType\": \"Ident\",\n        \"Name\": \"main\"\n      },\n      \"Type\": {\n        \"NodeType\": \"FuncType\",\n        \"TypeParams\": null,\n        \"Params\": {\n          \"NodeType\": \"FieldList\",\n          \"List\": null\n        },\n        \"Results\": null\n      },\n      \"Body\": {\n        \"NodeType\": \"BlockStmt\",\n        \"List\": [\n          {\n            \"NodeType\": \"ExprStmt\",\n            \"X\": {\n              \"NodeType\": \"CallExpr\",\n              \"Fun\": {\n                \"NodeType\": \"SelectorExpr\",\n                \"X\": {\n                  \"NodeType\": \"Ident\",\n                  \"Name\": \"fmt\"\n                },\n                \"Sel\": {\n                  \"NodeType\": \"Ident\",\n                  \"Name\": \"Println\"\n                }\n              },\n              \"Args\": [\n                {\n                  \"NodeType\": \"BasicLit\",\n                  \"Kind\": \"STRING\",\n                  \"Value\": \"\\\"hello world\\\"\"\n                }\n              ]\n            }\n          }\n        ]\n      }\n    }\n  ]\n}\n```\n\n## Install\n\nInstall `asty` under `$GOPATH/bin`\n\n```bash\ngo install github.com/asty-org/asty\n\nasty -h\n```\n\n## Building\n\nJust `make`\nIf you want to do it differently use `go build`\n\n## Usage\n\nConvert AST to JSON\n\n```bash\nasty go2json -input \u003cinput.go\u003e -output \u003coutput.json\u003e\n```\n\nConvert JSON to AST\n\n```bash\nasty json2go -input \u003cinput.json\u003e -output \u003coutput.go\u003e\n```\n\nUse `asty help` for more information\n\nUsing with docker\n\n```bash\ndocker run astyorg/asty go2json -input \u003cinput.go\u003e -output \u003coutput.json\u003e\n```\n\n## Development principles\n\n- Make json output as close to real golang structures as possible. There is no additional logic introduced.\n  No normalization. No reinterpretation. The only things that were introduced are the names of some enum values.\n- Make it very explicit. No reflection. No listing of fields. This is done to facilitate future maintenance.\n  If something will be changed in future versions of golang this code will probably break compile-time.\n- Keep polymorphism in JSON structure. If some field references _expression_ then particular type will be\n  discriminated from object type name stored in separate field.\n\n## Other solutions\n\n- https://github.com/ReconfigureIO/goblin reinterpret some structures (trying to simplify).\n  Out of maintenance for a long time. Still works in some forks.\n- https://github.com/CreativeInquiry/go2json tries to parse golang code with parser written in javascript.\n  Also lacks maintenance. Developed for particular use case of HaXe traspiler.\n\n## Article\n\nI wrote [an article](https://dev.to/evgenus/analyzing-ast-in-go-with-json-tools-36dg) about this project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasty-org%2Fasty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasty-org%2Fasty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasty-org%2Fasty/lists"}