The DS2 language does not include syntax for consuming text files. Downloading the JSON to a text file first means that you will have to load it into a table using other means before processing it with DS2. If you are having trouble with the size of the JSON, try making the response variable larger size. For example change this:
dcl varchar(65534) character set utf8 response;
to this:
dcl varchar(1000000) character set utf8 response;
You won't be able to store all 1000000 charactes in your VARCHAR variable to a table, but you can manipulate it with DS2, so you can parse the JSON text using the JSON package as shown in the example.
As for your second question, there really isn't a standard JSON structure - it's completely flexible. It is often useful to be able to prototype JSON data extraction routines to see how the tokens break out. Your could use code something like this:
/* Put some JSON in a macro variable for use in testing */
%let json= '{
"provider_urls": [
"https://www.modahealth.com/cms-data/providers-AK.json",
"https://www.modahealth.com/cms-data/providers-OR.json"
],
"formulary_urls": [
"https://www.modahealth.com/cms-data/drugs-AK.json",
"https://www.modahealth.com/cms-data/drugs-OR.json"
],
"plan_urls": [
"https://www.modahealth.com/cms-data/plans-AK.json",
"https://www.modahealth.com/cms-data/plans-OR.json"
]
}';
proc ds2;
data tokens/overwrite=yes;
dcl package json j();
dcl nchar(1024) token;
dcl int tokenType;
dcl char(1) string number bool_true bool_false delimiter;
method init();
dcl varchar(1000000) json;
dcl nchar(1024) thisVar;
dcl int rc parseFlags;
/* JSON for prototyping */
json=%superq(json);
rc = j.createParser();
if (rc) then do;
put 'Error' rc= ': Could not create JSON parser.';
stop;
end;
rc = j.setParserInput(json);
if (rc) then do;
put 'Error' rc= ': setParserInput failed.';
stop;
end;
/* Use the parser to parse the JSON */
/* RC of 0 means all went well. Otherwise, an error occurred */
do until (rc ne 0);
j.getNextToken( rc, token, tokenType, parseFlags );
string=if j.isstring(tokenType) then 'Y' else 'N';
number=if j.isnumeric(tokenType) then 'Y' else 'N';
bool_true=if j.isbooleantrue(tokenType) then 'Y' else 'N';
bool_false=if j.isbooleanfalse(tokenType) then 'Y' else 'N';
delimiter=if tokenType in (16,32,64,128) then 'Y' else 'N';
output;
end;
end;
enddata;
run;
quit;
proc print data=tokens; run;
and then look at how the JSON tokens parsed out:
... View more