I am trying to parse a .json file in SAS. To process lists in a .json file, I would like to remove all commas from [item1, item2, item3, .... itemn], but keep commas that are not in [].
I think I should do this using the prxchange regular expression ... I can make it work for two lists of elements, but I canβt figure out how to change it to work with lists of different amounts.
newvariable=prxchange('s/(\[\w+),(\w+\])/$1 $2',-1,oldvariable);
Examples:
oldvariable = "{"hospital": "NOP", "drugs": ["penicillin", "ampicillin", "cephalosporin"]}" newvariable = "{"hospital": "NOP", "drugs": ["penicillin" "ampicillin" "cephalosporin"]}" oldvariable = "{"hospital": "KOP", "drugs": ["tetracycline"]}" newvariable = "{"hospital": "KOP", "drugs": ["tetracycline"]}"
Perhaps there is a better way to approach this ...
source share