Yes, you can but you have to deal with more complex data structures in Perl. Have a look at perldsc.
In order to find out, what structure you need to create a desired JSON format, transform your JSON back into a Perl datastructure and use Data::Dumper to analyze it:
use strict;
use warnings;
use JSON;
use Data::Dumper;
my $js = <<'JSON';
{"contactsData":[{"m_UID":"963","m_display_name":"Lynne","m_emailList"
+:[{"m_emailID":"jhs@email.com","m_emailLabel":"","m_emailType":"2"}],
+"m_eventList":[{"m_startDate":"1991-10-25","m_eventLabel":"","m_etype
+":"1"}],"m_firstName":"Lynne","m_imList":[{"m_CustomProtocol":"test",
+"m_CustomType":"","m_imAddress":"Lynne","m_imProtocol":"-1","m_imType
+":"3"}],"m_isStarred":"1","m_lastName":"ROWLAND","m_middleName":"Lynn
+e","m_namePrefix":"","m_nameSuffix":"","m_nickname":"Lynne","m_note":
+"","m_organizationList":[{"m_JobDepartment":"","m_JobDescription":"",
+"m_OfficeLocation":"Ruzhou","m_OfficePhoneticName":"","m_OfficeSymbol
+":"","m_TypeLabel":"test","m_organizationName":"Rio Tinto Group","m_t
+itle":"","m_type":"0"}],"m_phoneNumberList":[{"m_label":"","m_number"
+:"9841003417","m_type":"21"}],"m_phonetic_fname":"Lynne","m_phonetic_
+lname":"Lynne","m_phonetic_mname":"Lynne","m_photoBitmap":"","m_posta
+lAddresses":[{"m_address":"787-4199 Orci Avenue","m_label":"","m_regi
+on":"West Africa","m_city":"Ruzhou","m_country":"Guinea-bissau","m_ne
+ighbourhood":"","m_PoBox":"251861","m_street":"","m_zipcode":"444610"
+,"m_type":"1"}],"m_source":"Google","m_vPredefinedTags":"1","websiteL
+ist":[{"m_website":"","m_websiteLabel":"","m_websiteType":"3"}],"rela
+tionship":[{"m_relationLabel":"","m_relationName":"ROWLAND","m_relati
+onType":"6"}],"socialList":[{"m_Type":"0","m_ProfileName":"ROWLAND","
+m_CustomProfileName":"test"}],"contactMatching":"true"} ]}
JSON
my $perl = from_json $js;
print Dumper $perl;
In your example, the output would begin like this:
$VAR1 = {
'contactsData' => [
{
'm_note' => '',
'm_display_name' => 'Lynne',
'relationship' => [
{
'm_relationName'
+ => 'ROWLAND',
'm_relationType'
+ => '6',
'm_relationLabel
+' => ''
}
],
'm_UID' => '963',
'm_lastName' => 'ROWLAND',
etc...
which means that you could create it like this:
my $perl;
$perl->{contactsData}->[0]->{m_note} = '';
$perl->{contactsData}->[0]->{m_display_name} = 'Lynne';
$perl->{contactsData}->[0]->{relationship}->[0]->{m_relationName} = 'R
+OWLAND';
...etc
Hope this helps.
|