+ Reply to Thread
Results 1 to 6 of 6

How to parse json with nested data?

  1. #1
    Registered User
    Join Date
    04-06-2015
    Location
    Chicago, IL
    MS-Off Ver
    Office 2013
    Posts
    7

    How to parse json with nested data?

    Segment of the json feed:

    Please Login or Register  to view this content.
    The following code will parse the "last name" field:

    Please Login or Register  to view this content.
    But can't figure out how to parse the "round1" total score which is nested in a second set of {} ?

    Any pointers would be much appreciated!

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: How to parse json with nested data?

    For parsing JSON in VBA, I've generally tended to use one of the libraries you can find on GitHub. For example:

    https://github.com/omegastripes/VBA-JSON-parser
    https://github.com/mlocati/vba-json

    I'm sure there are others.

    WBD
    Office 365 on Windows 11, looking for rep!

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: How to parse json with nested data?


    Json text format can also be directly parsed with VBA text functions or via a JScript evaluation like in post #9 of this thread

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: How to parse json with nested data?


    According to your segment :

    PHP Code: 
        With CreateObject("ScriptControl")
                 .
    Language "JScript"
            
    With .Eval("(" CF ")")
                
    Debug.Print "last_name    :  "; .last_namevbLf"round1.total : "CallByName(.round1"total"VbGet)
            
    End With
        End With 

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this !


    And the classic Split text VBA function for starters :

    PHP Code: 
        Dim S$(), L&, T$
            
    Split(CF"""id"" : """)
        For 
    1 To UBound(S)
            
    Split(S(L), """last_name""")(1)
            
    Debug.Print "Last Name    : "Split(T"""")(1); vbLf_
                        
    "Round1 Total : "Split(Split(Split(T"""round1""")(1), """total"" : ")(1), "}")(0)
        
    Next 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  6. #6
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: How to parse json with nested data?

    As a side note; you can not use the "MSScriptControl.ScriptControl" object directly in 64 Bit Excel.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Error trying to parse jSON file into excel sheet
    By soreno in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-21-2021, 09:19 AM
  2. Nested Json loop
    By xccel in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-11-2020, 09:22 PM
  3. Replies: 1
    Last Post: 09-10-2019, 02:05 PM
  4. [SOLVED] Programmatically find Dropbox folder path using VBA (Parse JSON)
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-12-2019, 09:23 PM
  5. avoid parse json errro 10001 stop
    By incobart in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-17-2017, 04:06 AM
  6. Use Excel VBA to Get and parse an API JSON response
    By proverbguy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-11-2017, 02:56 PM
  7. Parse / flatten nested JSON string in VBA
    By JasperD in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-23-2016, 08:45 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1