{"id":20940903,"url":"https://github.com/timhanewich/parse-json-in-excel","last_synced_at":"2026-03-19T18:07:49.369Z","repository":{"id":117078098,"uuid":"393486587","full_name":"TimHanewich/Parse-JSON-In-Excel","owner":"TimHanewich","description":"Brief tutorial on parsing JSON in a Microsoft Excel spreadsheet.","archived":false,"fork":false,"pushed_at":"2021-08-06T19:50:07.000Z","size":157,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-19T20:58:07.724Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TimHanewich.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-06T19:49:53.000Z","updated_at":"2023-01-10T01:56:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"6ed23f24-ce7e-4c3e-8f6c-ecf03605e5dc","html_url":"https://github.com/TimHanewich/Parse-JSON-In-Excel","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimHanewich%2FParse-JSON-In-Excel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimHanewich%2FParse-JSON-In-Excel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimHanewich%2FParse-JSON-In-Excel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimHanewich%2FParse-JSON-In-Excel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TimHanewich","download_url":"https://codeload.github.com/TimHanewich/Parse-JSON-In-Excel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243335385,"owners_count":20274898,"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":[],"created_at":"2024-11-18T23:12:19.042Z","updated_at":"2025-12-30T02:05:38.371Z","avatar_url":"https://github.com/TimHanewich.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# How to Parse JSON in an Excel Spreadsheet\nThis builds on the terrific work of [Daniel Ferry](https://www.linkedin.com/in/excelhero/). Daniel wrote a lightweight and convenient script for parsing and manipulating JSON in VBA. I extended this a little bit to allow for the reading of JSON from the spreadsheet alone - no need for VBA from the user's perspective.\n\n1. Enable developer mode in Excel\n![Enable developer mode](images/enable-developer.PNG)\n\n2. Under the developer tab in the ribbon, open **Visual Basic**\n![Open Visual Basic](images/open-visual-basic.PNG)\n\n3. Insert a new module\n![Insert new module](images/insert-module.PNG)\n\n4. Copy and paste the following code snipped into the module:\n```\n'-------------------------------------------------------------------\n' VBA JSON Parser\n'-------------------------------------------------------------------\nOption Explicit\nPrivate p\u0026, token, dic\nFunction ParseJSON(JSON$, Optional key$ = \"obj\") As Object\n    p = 1\n    token = Tokenize(JSON)\n    Set dic = CreateObject(\"Scripting.Dictionary\")\n    If token(p) = \"{\" Then ParseObj key Else ParseArr key\n    Set ParseJSON = dic\nEnd Function\nFunction ParseObj(key$)\n    Do: p = p + 1\n        Select Case token(p)\n            Case \"]\"\n            Case \"[\":  ParseArr key\n            Case \"{\"\n                       If token(p + 1) = \"}\" Then\n                           p = p + 1\n                           dic.Add key, \"null\"\n                       Else\n                           ParseObj key\n                       End If\n                \n            Case \"}\":  key = ReducePath(key): Exit Do\n            Case \":\":  key = key \u0026 \".\" \u0026 token(p - 1)\n            Case \",\":  key = ReducePath(key)\n            Case Else: If token(p + 1) \u003c\u003e \":\" Then dic.Add key, token(p)\n        End Select\n    Loop\nEnd Function\nFunction ParseArr(key$)\n    Dim e\u0026\n    Do: p = p + 1\n        Select Case token(p)\n            Case \"}\"\n            Case \"{\":  ParseObj key \u0026 ArrayID(e)\n            Case \"[\":  ParseArr key\n            Case \"]\":  Exit Do\n            Case \":\":  key = key \u0026 ArrayID(e)\n            Case \",\":  e = e + 1\n            Case Else: dic.Add key \u0026 ArrayID(e), token(p)\n        End Select\n    Loop\nEnd Function\n'-------------------------------------------------------------------\n' Support Functions\n'-------------------------------------------------------------------\nFunction Tokenize(s$)\n    Const Pattern = \"\"\"(([^\"\"\\\\]|\\\\.)*)\"\"|[+\\-]?(?:0|[1-9]\\d*)(?:\\.\\d*)?(?:[eE][+\\-]?\\d+)?|\\w+|[^\\s\"\"']+?\"\n    Tokenize = RExtract(s, Pattern, True)\nEnd Function\nFunction RExtract(s$, Pattern, Optional bGroup1Bias As Boolean, Optional bGlobal As Boolean = True)\n  Dim c\u0026, m, n, v\n  With CreateObject(\"vbscript.regexp\")\n    .Global = bGlobal\n    .MultiLine = False\n    .IgnoreCase = True\n    .Pattern = Pattern\n    If .TEST(s) Then\n      Set m = .Execute(s)\n      ReDim v(1 To m.Count)\n      For Each n In m\n        c = c + 1\n        v(c) = n.Value\n        If bGroup1Bias Then If Len(n.submatches(0)) Or n.Value = \"\"\"\"\"\" Then v(c) = n.submatches(0)\n      Next\n    End If\n  End With\n  RExtract = v\nEnd Function\nFunction ArrayID$(e)\n    ArrayID = \"(\" \u0026 e \u0026 \")\"\nEnd Function\nFunction ReducePath$(key$)\n    If InStr(key, \".\") Then ReducePath = Left(key, InStrRev(key, \".\") - 1) Else ReducePath = key\nEnd Function\nFunction ListPaths(dic)\n    Dim s$, v\n    For Each v In dic\n        s = s \u0026 v \u0026 \" --\u003e \" \u0026 dic(v) \u0026 vbLf\n    Next\n    Debug.Print s\nEnd Function\nFunction GetFilteredValues(dic, match)\n    Dim c\u0026, i\u0026, v, w\n    v = dic.keys\n    ReDim w(1 To dic.Count)\n    For i = 0 To UBound(v)\n        If v(i) Like match Then\n            c = c + 1\n            w(c) = dic(v(i))\n        End If\n    Next\n    ReDim Preserve w(1 To c)\n    GetFilteredValues = w\nEnd Function\nFunction GetFilteredTable(dic, cols)\n    Dim c\u0026, i\u0026, j\u0026, v, w, z\n    v = dic.keys\n    z = GetFilteredValues(dic, cols(0))\n    ReDim w(1 To UBound(z), 1 To UBound(cols) + 1)\n    For j = 1 To UBound(cols) + 1\n         z = GetFilteredValues(dic, cols(j - 1))\n         For i = 1 To UBound(z)\n            w(i, j) = z(i)\n         Next\n    Next\n    GetFilteredTable = w\nEnd Function\nFunction OpenTextFile$(f)\n    With CreateObject(\"ADODB.Stream\")\n        .Charset = \"utf-8\"\n        .Open\n        .LoadFromFile f\n        OpenTextFile = .ReadText\n    End With\nEnd Function\n\n'-------------------------------------------------------------------\n' Functions to allow JSON parsing in spreadsheet\n'-------------------------------------------------------------------\nFunction JSON(body$, path$)\n    Set dic = ParseJSON(body)\n    JSON = dic(path)\nEnd Function\n```\n5. Close the code editor mini-window and the Visual Basic editor window. You should now be back in the spreadsheet.\n\n6. Example JSON parsing and value extracting\n![Example JSON parsing](images/example-json.PNG)\n\nThere are additional example on how to use this function to extract embedded objects or get a specific object in an array of objects. You can find these examples in the [Example Spreadsheet](Example.xlsm).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimhanewich%2Fparse-json-in-excel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimhanewich%2Fparse-json-in-excel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimhanewich%2Fparse-json-in-excel/lists"}