Reputation: 955
I have a JSON whcih i am trying to modify using perl code.
{
"Person":{
"personalData": {
"workList": {
"file":{
"fileName": "/usr/temp/ABC.txt" }
},
}
}
}
}
I need to convert the above JSON into something like this:
{
"Person":{
"personalData": {
"workList": {
"directoryList":{
"directory":[
"file":{
"fileName": "/usr/temp/ABC.txt" }
}
]
}
}
}
}
}
Can someone give some example of doing this in perl.
Upvotes: 1
Views: 105
Reputation: 118605
$data->{Person}{personalData}{workList}{directoryList}{directory} =
[ delete $data->{Person}{personalData}{workList}{file} ];
Or more concisely,
$tmp = $data->{Person}{personalData}{workList};
$tmp->{directoryList}{directory} = [ delete $tmp->{file} ];
For an explanation of how this works see: How to replace a Perl hash key?
Upvotes: 2