BookmarkSubscribeRSS Feed
ellen09
Fluorite | Level 6

Hi,

 

I retrieve a JSON file which looks like below, and I am trying to parse it. The value of name "C" is quoted as a string, however, it is also an array. I am trying to parse it with both libname json engine and DS2 procedure, but I don't know how to parse inside the value of "C".  Any help appreciated!

 

{
"result": {
"status": "good"
},
"reviews": [
{
"A": 32,
"B": "name1",
"C": "{\"x1\": {\n \"A1\": {\"y1\": [\n {\n \"fname\": \"p1\",\n \"mname\": \"p2\",\n }\n ]\n}}",
"D": "New"
},
{
"A": 38,
"B": "name2",
"C": "{\"x1\": {\n \"B1\": {\"y1\": [\n {\n \"fname\": \"q1\",\n \"mname\": \"q2\",\n }\n ]\n}}",
"D": "New"
}
]
}

4 REPLIES 4
ellen09
Fluorite | Level 6

I am hoping to get a data set like this:

Capture.PNG

 

 

ChrisNZ
Tourmaline | Level 20

The simplest if the JSON's structure is quite constant:

FNAME=scan(C, 9,':\"{}');

MNAME=scan(C,12,':\"{}');

 

If the string varies more, you may have to look for the positions of fname and mname.

 

If it varies a lot, you may have to resort to regular expressions to isolate the bits you want, or use several statements.

 

A data step allows you to read the JSON string using an input statement, but DS2 cannot afaik:

https://communities.sas.com/t5/SAS-Data-Management/Parsing-a-string-variable/td-p/157459

 

 

 

ellen09
Fluorite | Level 6
That helps. Thank you

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1456 views
  • 0 likes
  • 2 in conversation