So I am going to preface this by saying I came up with this using RegExr and just typing in random thing until I got what I needed.
The goal I had in mind was to generate an array from a json string using.
my @valuesArray=$msgPayload=~/((?=["]).+?(?=["])")/g;
This works for most cases, however it just selects values from one quote to the next quote. this becomes an issue when there is a value like true, false, or null.
Example String
..."email":"","lastLogon":null,"pwdChanged":"0","status":"A","phoneNumber":"","extension":"","locale":"en_US","boChecked":false,"boUserId":"","UserId":"TWEH","sChecked":false,...
So I am working around this by using multiple replaces before actually splitting up into an array.
$msgPayload =~ s/:true/:"true"/g;
$msgPayload =~ s/:false/:"false"/g;
$msgPayload =~ s/:null/:"null"/g;
my @valuesArray=$msgPayload=~/((?=["]).+?(?=["])")/g;
Now I was wondering if there was a way to combine all of this into a single regex expresion where it can also select the true false and null values without first having to do the replace. And if it is possible I feel like it would be more efficient doing it that way, but if I wrong, I would love to know more.
Thanks!
Edit: We don't have any modules installed, and I doubt I could get any installed for this project since it is so small. I am just trying to make due with what I have.
The data is stored in a varchar column in a table. One full example would be received like so.
[ { "signonId" : "", "userId" : "USERNAME", "groupID" : "Master", "userName" : "", "phoneNumber" : "", "extension" : "4444", "emailAddress" : "", "password" : "", "locale" : ""}, { "signonId" : "", "userId" : "USERNAME", "groupID" : "Master", "userName" : "", "phoneNumber" : "", "extension" : "5555", "emailAddress" : "", "password" : "", "locale" : ""} ]
Which then when you replace the " with " and format it, it becomes...
[
{
"signonId":"",
"userId":"USERNAME",
"groupID":"Master",
"userName":"",
"phoneNumber":"",
"extension":"4444",
"emailAddress":"",
"password":"",
"locale":""
},
{
"signonId":"",
"userId":"USERNAME",
"groupID":"Master",
"userName":"",
"phoneNumber":"",
"extension":"5555",
"emailAddress":"",
"password":"",
"locale":""
}
]