How to parse json string which has more than 32767 characters in SAS?
sample of json string (Response key):
{"message"="1000 records found","status"="200","Respone"="[{\"name\":\"Jhon\",\"age\":22,\"class\":\"mca\"},{\"name\":\"Victor\",\"age\":22,\"class\":\"mca\"}]"}
above sample json has been parsed in python using json.loads() function can anyone suggest the alternative in sas
Also you could use data step to parse JSON file.
data have; infile 'c:\temp\have.json' recfm=n dlm='{[,]}'; input have : $2000.; run;
The following macro will give you the tools to load a JSON file into a LUA table. Variables in LUA have no max-length (limited only by memory) so you can perform any processing you need there (using proc lua) before dropping back to SAS.
https://core.sasjs.io/ml__json_8sas_source.html
Sure, here you go:
filename fref1 "/path/to/json.file";
/* compile the lua JSON module */
%ml_json()
/* create LUA code */
data _null_;
file "/path/to/file.lua";
put '
infile = io.open (sas.symget("fpath1"), "r")
io.input(infile)
local resp=json.decode(io.read())
-- grab an element from the LUA table
local logloc=resp["logLocation"]
io.close(infile)
';
run;
/* execute LUA */
%inc "/path/to/file.lua";
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.