Parse JSON with VBA

kanvian

New Member
Joined
May 26, 2014
Messages
1
Hi everybody,

I would like to parse a json string in VBA using this library :
VB JSON Parser Library for VB6 (BSD Licensed) - Visual Basic, JSON

here is an example of the json string I receive from a Web Service and want to parse:


{
"total": [[10000,1]],
"periods": [1399852800000],
"series": {"A": [[102,20]],"B": [[13,25]],"C": [[189,55]]},
"meta": {
"versions": {"selected": ["all"],"available": ["all","2.0","1.0","unknown"]},
"series": ["A","B","C",],
"time-zone": "Coordinated Universal Time",
"alternative-exports": ["csv"],
"period": "2014-05-12:2014-05-18",
}
}

here is the code I wrote in VBA (jsonText is the json string above):

Dim jsonObj As Dictionary​
Set jsonObj = json.parse(jsonText)​

Unfortunately it does not work, the dictionary I obtain (jsonObj) seems to contain only 2 keys (total and periods). Therefore I cannot build this table in excel:

ABC
10213189

<tbody>
</tbody>


Does anyone have any ideas to solve this problem ?
Thank you very much for reading and help.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Late to this, but paste the code to jslint.com and it errors because
"series": {"A": [[102,20]],"B": [[13,25]],"C": [[189,55]]}, has [[ and ]]
and also with
"series": ["A","B","C",], is wrong - there should be not , before ]
and
"period": "2014-05-12:2014-05-18", has a trailing ,

This validates but I am not sure if it is what you expect:
{
"total": [
[
10000,
1
]
],
"periods": [
1399852800000
],
"series": {
"A": [
102,
20
],
"B": [
13,
25
],
"C": [
189,
55
]
},
"meta": {
"versions": {
"selected": [
"all"
],
"available": [
"all",
"2.0",
"1.0",
"unknown"
]
},
"series": [
"A",
"B",
"C"
],
"time-zone": "Coordinated Universal Time",
"alternative-exports": [
"csv"
],
"period": "2014-05-12:2014-05-18"
}
}
 
Upvote 0

Forum statistics

Threads
1,214,974
Messages
6,122,536
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top