example:data.json
- {
- {
- "id":"John" ,
- "password":"Doe"
- },
-
- {
- "id":"Ben" ,
- "password":"123"
- }
- }
复制代码%macro JSONParse(Filename, varList);
data JSON (keep=&varlist record);
infile &FILENAME ;
input;
ExpressionID = prxparse('/{(.*?)}/');
jsontext = _INFILE_;
start = 1;
stop = length(jsontext);
array vlist $50 &Varlist;
call prxnext(ExpressionID, start, stop, jsontext, position, length);
do while (position > 0);
newpos = position + 1;
newlen = length - 2;
record = substr(jsontext, newpos, newlen);
i=0;
do over vlist;
i+1;
vlist = strip(compress(scan(scan( record, i, ","), 2, ":"), '"'));
end;
output;
call prxnext(ExpressionID, start, stop, jsontext, position, length);
end;
run;
%mend;
FILENAME TEST "\data.json";
%JSONParse(TEST, id password);