As the notice in parentheses in the title states, this is some code for parsing a JSON string and this code is not an API. So far, I've only tested it on JSON responses from my API projects. Those responses have zero whitespace which makes it easy to standardize this function. HOWEVER, other JSON files or strings from other sources might have whitespace and would not work properly with what this is. I'll end up copying all my API projects into one thread and updating their source codes with these functions so they work in a more friendly manner. I had tried to use Galleon's qb_framework and it was a total mess. No documentation that I could find anywhere and so I couldn't even begin to figure out how to translate a JSON to plain text with that. However, I will use it for generating JSON response files at some point because it can do that and it looks like it does it quite well. Anyways, enough rambling. Here is the code for my JSON parsing. I've attached three JSON files from API projects I've worked on so you can test both functions. GetKey will grab the first instance of that key. Useful for a file that has ONE response. GetAllKey will return an array containing all values for that keyname in the JSON file:
'OPEN "nasapod.json" FOR BINARY AS #1
'OPEN "sentimapi.json" FOR BINARY AS #1
'PRINT GetKey("title", JSON) 'for use with nasapod
'PRINT GetKey("url", JSON) 'for use with nasapod
'PRINT GetKey("explanation", JSON) 'for use with nasapod
'REDIM Polarity(0) AS STRING 'for use with sentimapi
PRINT GetKey
("delivery_line_1", JSON
) 'for use with adddressvalidation PRINT GetKey
("last_line", JSON
) 'for use with addressvalidation PRINT GetKey
("county_name", JSON
) 'for use with addressvalidation
'GetAllKey "polarity", JSON, Polarity() 'for use with sentimapi
'DIM i
'FOR i = 1 TO UBOUND(Polarity) 'for use with sentimapi
' PRINT Polarity(i)
'NEXT
jkey
= MID$(jkey
, 1, LEN(jkey
) - 1) GetKey = ""
GetKey = jkey
x = x + 1
jkey = JSON
jkey
= MID$(jkey
, 1, LEN(jkey
) - 1) ParseKey(x) = jkey