XSLT to convert XML to JSON Array - arrays

I am currently using SAP CPI to achieve this conversion. I have tried the regular XML to JSON converter available but was not able to achieve this requirement. I then set out to try and see if XSLT can help.
I am trying to convert the following XML payload:
<root>
<ClientID>1</ClientID>
<PackageID>650</PackageID>
<SBUID>2187</SBUID>
<CandidateID>456</CandidateID>
<AssociateId>789</AssociateId>
<FirstName>Meghana</FirstName>
<MiddleName></MiddleName>
<LastName>Rao</LastName>
<FatherName>Satish</FatherName>
<ContactNo>7530001169</ContactNo>
<EmailID>dummy#sap.com</EmailID>
<AddressHistory>
<Address>
<SequenceNo>0</SequenceNo>
<AddressLine>Kharghar,navi mumbai</AddressLine>
<City>Maharashtra-Mumbai</City>
<State>Maharashtra</State>
<PinCode>410210</PinCode>
<Country>India</Country>
<Landmark></Landmark>
<StayFrom>01-08-2013</StayFrom>
<StayTo>06-08-2021</StayTo>
<IsCurrentAddress>false</IsCurrentAddress>
<IsPermanentAddress>false</IsPermanentAddress>
<HouseNo></HouseNo>
<AddressType>Current</AddressType>
<DocList>
<listofdocs>
<DocumentName>abc.jpg</DocumentName>
<DocumentPath>base64</DocumentPath>
</listofdocs>
</DocList>
</Address>
</AddressHistory>
<EducationList>
<Education>
<SequenceNo>0</SequenceNo>
<Qualification></Qualification>
<Degree>Under Graduate Degree</Degree>
<CollegeName>Amrutvahini College of engineering, Sangamner (Pune University)</CollegeName>
<Location></Location>
<RollNumber>123123</RollNumber>
<UniversityName>Mumbai University</UniversityName>
<UniversityAddress></UniversityAddress>
<PeriodFrom></PeriodFrom>
<PeriodTo></PeriodTo>
<YearOfPassing>2014</YearOfPassing>
<Zipcode></Zipcode>
<Percentage></Percentage>
<AdditionalRemarks>10th/12th/Undergrad etc</AdditionalRemarks>
<International>false</International>
<Country></Country>
<DocList>
<listofdocs>
<DocumentName>abc.jpg</DocumentName>
<DocumentPath>base64</DocumentPath>
</listofdocs>
</DocList>
</Education>
</EducationList>
<EmploymentList>
<Employment>
<SequenceNo>0</SequenceNo>
<EmployerName>Stravis Solutions</EmployerName>
<EmployerAddress>Bangalore</EmployerAddress>
<EmployerContactNo></EmployerContactNo>
<Designation>SDE</Designation>
<EmployeeID>asdas</EmployeeID>
<FixedSalary>0</FixedSalary>
<IsCurrentEmployment>false</IsCurrentEmployment>
<RelievingDate>15-10-2021</RelievingDate>
<State></State>
<City></City>
<Zipcode></Zipcode>
<International>false</International>
<Country></Country>
<PFNumber></PFNumber>
<UANNumber></UANNumber>
<DocList>
<listofdocs>
<DocumentName>abc.jpg</DocumentName>
<DocumentPath>base64</DocumentPath>
</listofdocs>
</DocList>
<DateOfJoining>18-03-2015</DateOfJoining>
</Employment>
<Employment>
<SequenceNo>0</SequenceNo>
<EmployerName>Stravis Solutions</EmployerName>
<EmployerAddress>Bangalore</EmployerAddress>
<EmployerContactNo></EmployerContactNo>
<Designation>SDE</Designation>
<EmployeeID>asdas</EmployeeID>
<FixedSalary>0</FixedSalary>
<IsCurrentEmployment>false</IsCurrentEmployment>
<RelievingDate>15-10-2021</RelievingDate>
<International>false</International>
<Country></Country>
<PFNumber></PFNumber>
<UANNumber></UANNumber>
<DocList>
<listofdocs>
<DocumentName>abc.jpg</DocumentName>
<DocumentPath>base64</DocumentPath>
</listofdocs>
</DocList>
<DateOfJoining>18-03-2015</DateOfJoining>
</Employment>
</EmploymentList>
<AddressReferencesList>
<ListofReferences>
<OrganizationName>Com 1</OrganizationName>
<AdditionalRemarks></AdditionalRemarks>
<NameOfReferee>Ref1</NameOfReferee>
<RefereeOccupation>SDE</RefereeOccupation>
<RefereePhoneNumber>123456</RefereePhoneNumber>
<RefereeEmailAddress>Ref1#com1.com</RefereeEmailAddress>
</ListofReferences>
<ListofReferences>
<OrganizationName>Com 1</OrganizationName>
<AdditionalRemarks></AdditionalRemarks>
<NameOfReferee>Ref1</NameOfReferee>
<RefereeOccupation>SDE</RefereeOccupation>
<RefereePhoneNumber>123456</RefereePhoneNumber>
<RefereeEmailAddress>Ref1#com1.com</RefereeEmailAddress>
</ListofReferences>
</AddressReferencesList>
<DOB>03-08-2021</DOB>
<DLDetails>
<DOB>03-08-2021</DOB>
<ApplicantName>Test</ApplicantName>
<FatherName>Test</FatherName>
<dl_remarks></dl_remarks>
<UniqueIDCode>1231231</UniqueIDCode>
<DocList>
<listofdocs>
<DocumentName>abc.jpg</DocumentName>
<DocumentPath>base64</DocumentPath>
</listofdocs>
</DocList>
</DLDetails>
<PanDetails>
<DOB>03-08-2021</DOB>
<ApplicantName>Sunil Kumar Yadav</ApplicantName>
<FatherName>Sunil</FatherName>
<pan_remarks></pan_remarks>
<UniqueIDCode>23123131</UniqueIDCode>
<DocList>
<listofdocs>
<DocumentName>abc.jpg</DocumentName>
<DocumentPath>base64</DocumentPath>
</listofdocs>
</DocList>
</PanDetails>
<PVWDetails>
<AddressList>
<Address>
<SequenceNo>0</SequenceNo>
<AddressLine>Kharghar,navi mumbai</AddressLine>
<City>Maharashtra-Mumbai</City>
<State>Maharashtra</State>
<PinCode>410210</PinCode>
<Country>India</Country>
<Landmark></Landmark>
<StayFrom>01-08-2013</StayFrom>
<StayTo>06-08-2021</StayTo>
<IsCurrentAddress>false</IsCurrentAddress>
<IsPermanentAddress>false</IsPermanentAddress>
<HouseNo>Sai shradha CHS.Sector-11,</HouseNo>
<AddressType>Current</AddressType>
<DocList>
<listofdocs>
<DocumentName>abc.jpg</DocumentName>
<DocumentPath>base64</DocumentPath>
</listofdocs>
</DocList>
</Address>
</AddressList>
<DOB>03-08-2021</DOB>
<FatherName>Sunil</FatherName>
<ApplicantName>Sunil Kumar Yadav</ApplicantName>
</PVWDetails>
<CreditDetail>
<ApplicantName>Test</ApplicantName>
<DOB>03-08-2021</DOB>
<FatherName>Test</FatherName>
<Gender>Male</Gender>
<UniqueIDCode>Pan Number</UniqueIDCode>
<EmailID>asda#gmail.com</EmailID>
<DocList>
<listofdocs>
<DocumentName>abc.jpg</DocumentName>
<DocumentPath>base64</DocumentPath>
</listofdocs>
</DocList>
</CreditDetail>
<DrugTestPanelCheck>
<DrugTestPanel>DrugTestPanel5</DrugTestPanel>
<ApplicantName>Test Candidate</ApplicantName>
</DrugTestPanelCheck>
<GDCDetails>
<ApplicantName>Sunil Kumar Yadav</ApplicantName>
<DOB>03-08-2021</DOB>
<FatherName>Sunil</FatherName>
</GDCDetails>
<PassportCheckDetails>
<NameInPassport>Sunil Kumar Yadav</NameInPassport>
<PassportNo>1231231</PassportNo>
<MachineReadableZone></MachineReadableZone>
<CandidateFirstName>Sunil</CandidateFirstName>
<CandidateLastName>Yadav</CandidateLastName>
<DOB>03-08-2021</DOB>
<FatherName>Sunil</FatherName>
<DocList>
<listofdocs>
<DocumentName>abc.jpg</DocumentName>
<DocumentPath>base64</DocumentPath>
</listofdocs>
</DocList>
</PassportCheckDetails>
</root>
To the below JSON payload, which as you can see has multiple array elements for even single payloads:
{
"ClientID": "1",
"PackageID": "650",
"SBUID": "2187",
"CandidateID": "456",
"AssociateId": "789",
"FirstName": "Meghana",
"MiddleName": "",
"LastName": "Rao",
"FatherName": "Satish",
"ContactNo": "7530001169",
"EmailID": "dummy#sap.com",
"AddressHistory": {
"Address": [
{
"SequenceNo": "0",
"AddressLine": "Kharghar,navi mumbai",
"City": "Maharashtra-Mumbai",
"State": "Maharashtra",
"PinCode": "410210",
"Country": "India",
"Landmark": "",
"StayFrom": "01-08-2013",
"StayTo": "06-08-2021",
"IsCurrentAddress": false,
"IsPermanentAddress": false,
"HouseNo": "",
"AddressType": "Current",
"DocList": {
"listofdocs": [
{
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
]
}
}
]
},
"EducationList": {
"Education": [
{
"SequenceNo": "0",
"Qualification": "",
"Degree": "Under Graduate Degree",
"CollegeName": "Amrutvahini College of engineering, Sangamner (Pune University)",
"Location": "",
"RollNumber": "123123",
"UniversityName": "Mumbai University",
"UniversityAddress": "",
"PeriodFrom": "",
"PeriodTo": "",
"YearOfPassing": "2014",
"Zipcode": "",
"Percentage": "",
"AdditionalRemarks": "10th/12th/Undergrad etc",
"International": false,
"Country": "",
"DocList": {
"listofdocs": [
{
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
]
}
}
]
},
"EmploymentList": {
"Employment": [
{
"SequenceNo": "0",
"EmployerName": "Stravis Solutions",
"EmployerAddress": "Bangalore",
"EmployerContactNo": "",
"Designation": "SDE",
"EmployeeID": "asdas",
"FixedSalary": "0",
"IsCurrentEmployment": false,
"RelievingDate": "15-10-2021",
"Zipcode": "",
"International": false,
"Country": "",
"PFNumber": "",
"UANNumber": "",
"DocList": {
"listofdocs": [
{
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
]
},
"DateOfJoining": "18-03-2015"
},
{
"SequenceNo": "0",
"EmployerName": "Stravis Solutions",
"EmployerAddress": "Bangalore",
"EmployerContactNo": "",
"Designation": "SDE",
"EmployeeID": "asdas",
"FixedSalary": "0",
"IsCurrentEmployment": false,
"RelievingDate": "15-10-2021",
"Zipcode": "",
"International": false,
"Country": "",
"PFNumber": "",
"UANNumber": "",
"DocList": {
"listofdocs": [
{
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
]
},
"DateOfJoining": "18-03-2015"
}
]
},
"AddressReferencesList": {
"ListofReferences": [
{
"OrganizationName": "Com 1",
"AdditionalRemarks": "",
"NameOfReferee": "Ref1",
"RefereeOccupation": "SDE",
"RefereePhoneNumber": "123456",
"RefereeEmailAddress": "Ref1#com1.com"
},
{
"OrganizationName": "Com 1",
"AdditionalRemarks": "",
"NameOfReferee": "Ref2",
"RefereeOccupation": "SDE",
"RefereePhoneNumber": "123456",
"RefereeEmailAddress": "Ref1#com1.com"
}
]
},
"DOB": "03-08-2021",
"DLDetails": {
"DOB": "03-08-2021",
"ApplicantName": "Test",
"FatherName": "Test",
"UniqueIDCode": "1231231",
"DocList": {
"listofdocs": [
{
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
]
}
},
"PanDetails": {
"DOB": "03-08-2021",
"ApplicantName": "Sunil Kumar Yadav",
"FatherName": "Sunil",
"UniqueIDCode": "23123131",
"DocList": {
"listofdocs": [
{
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
]
}
},
"PVWDetails": {
"AddressList": {
"Address": [
{
"SequenceNo": "0",
"AddressLine": "Kharghar,navi mumbai",
"City": "Maharashtra-Mumbai",
"State": "Maharashtra",
"PinCode": "410210",
"Country": "India",
"Landmark": "",
"StayFrom": "01-08-2013",
"StayTo": "06-08-2021",
"IsCurrentAddress": false,
"IsPermanentAddress": false,
"HouseNo": "Sai shradha CHS.Sector-11,",
"AddressType": "Current",
"DocList": {
"listofdocs": [
{
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
]
}
}
]
},
"DOB": "03-08-2021",
"FatherName": "Sunil",
"ApplicantName": "Sunil Kumar Yadav"
},
"CreditDetail": {
"ApplicantName": "Test",
"DOB": "03-08-2021",
"FatherName": "Test",
"Gender": "Male",
"UniqueIDCode": "Pan Number",
"EmailID": "asda#gmail.com",
"DocList": {
"listofdocs": [
{
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
]
}
},
"PassportCheckDetails": {
"NameInPassport": "Sunil Kumar Yadav",
"PassportNo": "1231231",
"MachineReadableZone": "",
"CandidateFirstName": "Sunil",
"CandidateLastName": "Yadav",
"DOB": "03-08-2021",
"FatherName": "Sunil",
"DocList": {
"listofdocs": [
{
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
]
}
}
}
As you can see, there is an array created for every part of the data. How can I achieve this with XSLT?
Whatever code i have tried with so far, the converted JSON has not had any arrays barring cases where there are multiple records under a root.
I have tried variations of the following code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://use your namespace">
<xsl:output method="text"/>
<xsl:template match="/ns0:Account_Resp">{
<xsl:apply-templates select="*"/> }
</xsl:template>
<!-- Object or Element Property-->
<xsl:template match="*">
"<xsl:value-of select="name()"/>" : <xsl:call-template name="Properties"/>
</xsl:template>
<!-- Array Element -->
<xsl:template match="*" mode="ArrayElement">
<xsl:call-template name="Properties"/>
</xsl:template>
<!-- Object Properties -->
<xsl:template name="Properties">
<xsl:variable name="childName" select="name(*[1])"/>
<xsl:choose>
<xsl:when test="not(*|#*)">"<xsl:value-of select="."/>"</xsl:when>
<xsl:when test="count(*[name()=$childName]) > 1">{ "<xsl:value-of select="$childName"/>" :[<xsl:apply-templates select="*" mode="ArrayElement"/>] }</xsl:when>
<xsl:otherwise>{
<xsl:apply-templates select="#*"/>
<xsl:apply-templates select="*"/>
}</xsl:otherwise>
</xsl:choose>
<xsl:if test="following-sibling::*">,</xsl:if>
</xsl:template>
<!-- Attribute Property -->
<xsl:template `enter code here`match="#*">"<xsl:value-of select="name()"/>" : "<xsl:value-of select="."/>",
</xsl:template>
</xsl:stylesheet>
And received the following output - in which you can see that for single payloads, an array is not getting created:
{
"ClientID" : "1",
"PackageID" : "650",
"SBUID" : "2187",
"CandidateID" : "456",
"AssociateId" : "789",
"FirstName" : "Meghana",
"MiddleName" : "",
"LastName" : "Rao",
"FatherName" : "Satish",
"ContactNo" : "7530001169",
"EmailID" : "dummy#sap.com",
"AddressHistory" : { "Address" :[{
"SequenceNo" : "0",
"AddressLine" : "Kharghar,navi mumbai",
"City" : "Maharashtra-Mumbai",
"State" : "Maharashtra",
"PinCode" : "410210",
"Country" : "India",
"Landmark" : "",
"StayFrom" : "01-08-2013",
"StayTo" : "06-08-2021",
"IsCurrentAddress" : "false",
"IsPermanentAddress" : "false",
"HouseNo" : "",
"AddressType" : "Current",
"DocList" : { "listofdocs" :[{
"DocumentName" : "abc.jpg",
"DocumentPath" : "base64"
}] }
},{
"SequenceNo" : "1",
"AddressLine" : "Kharghar,navi mumbai",
"City" : "Maharashtra-Mumbai",
"State" : "Maharashtra",
"PinCode" : "410210",
"Country" : "India",
"Landmark" : "",
"StayFrom" : "01-08-2013",
"StayTo" : "06-08-2021",
"IsCurrentAddress" : "false",
"IsPermanentAddress" : "false",
"HouseNo" : "",
"AddressType" : "Current",
"DocList" : { "listofdocs" :[{
"DocumentName" : "def.jpg",
"DocumentPath" : "base64"
}] }
}] },
"EducationList" : {
"Education" : {
"SequenceNo" : "0",
"Qualification" : "",
"Degree" : "Under Graduate Degree",
"CollegeName" : "Amrutvahini College of engineering, Sangamner (Pune University)",
"Location" : "",
"RollNumber" : "123123",
"UniversityName" : "Mumbai University",
"UniversityAddress" : "",
"PeriodFrom" : "",
"PeriodTo" : "",
"YearOfPassing" : "2014",
"Percentage" : "",
"AdditionalRemarks" : "10th/12th/Undergrad etc",
"International" : "false",
"Country" : "",
"DocList" : { "listofdocs" :[{
"DocumentName" : "def.jpg",
"DocumentPath" : "base64"
}] }
}
},
"EmploymentList" : { "Employment" :[{
"SequenceNo" : "0",
"EmployerName" : "Stravis Solutions",
"EmployerAddress" : "Bangalore",
"EmployerContactNo" : "",
"Designation" : "SDE",
"EmployeeID" : "asdas",
"FixedSalary" : "0",
"IsCurrentEmployment" : "false",
"RelievingDate" : "15-10-2021",
"Zipcode" : "",
"International" : "false",
"Country" : "",
"PFNumber" : "",
"UANNumber" : "",
"DocList" : {
"listofdocs" : {
"DocumentName" : "abc.jpg",
"DocumentPath" : "base64"
}
},
"DateOfJoining" : "18-03-2015"
},{
"SequenceNo" : "1",
"EmployerName" : "Stravis Solutions",
"EmployerAddress" : "Bangalore",
"EmployerContactNo" : "",
"Designation" : "SDE",
"EmployeeID" : "asdas",
"FixedSalary" : "0",
"IsCurrentEmployment" : "false",
"RelievingDate" : "15-10-2021",
"Zipcode" : "",
"International" : "false",
"Country" : "",
"PFNumber" : "",
"UANNumber" : "",
"DocList" : {
"listofdocs" : {
"DocumentName" : "def.jpg",
"DocumentPath" : "base64"
}
},
"DateOfJoining" : "18-03-2015"
}] },
"AddressReferencesList" : { "ListofReferences" :[{
"OrganizationName" : "Com 1",
"AdditionalRemarks" : "",
"NameOfReferee" : "Ref1",
"RefereeOccupation" : "SDE",
"RefereePhoneNumber" : "123456",
"RefereeEmailAddress" : "Ref1#com1.com"
},{
"OrganizationName" : "Com 1",
"AdditionalRemarks" : "",
"NameOfReferee" : "Ref2",
"RefereeOccupation" : "SDE",
"RefereePhoneNumber" : "123456",
"RefereeEmailAddress" : "Ref1#com1.com"
}] },
"DOB" : "03-08-2021",
"DLDetails" : {
"DOB" : "03-08-2021",
"ApplicantName" : "Test",
"FatherName" : "Test",
"UniqueIDCode" : "1231231",
"DocList" : {
"listofdocs" : {
"DocumentName" : "abc.jpg",
"DocumentPath" : "base64"
}
}
},
"PanDetails" : {
"DOB" : "03-08-2021",
"ApplicantName" : "Sunil Kumar Yadav",
"FatherName" : "Sunil",
"UniqueIDCode" : "23123131",
"DocList" : {
"listofdocs" : {
"DocumentName" : "abc.jpg",
"DocumentPath" : "base64"
}
}
},
"PVWDetails" : {
"AddressList" : {
"Address" : {
"SequenceNo" : "0",
"AddressLine" : "Kharghar,navi mumbai",
"City" : "Maharashtra-Mumbai",
"State" : "Maharashtra",
"PinCode" : "410210",
"Country" : "India",
"Landmark" : "",
"StayFrom" : "01-08-2013",
"StayTo" : "06-08-2021",
"IsCurrentAddress" : "false",
"IsPermanentAddress" : "false",
"HouseNo" : "Sai shradha CHS.Sector-11,",
"AddressType" : "Current"
}
},
"DOB" : "03-08-2021",
"FatherName" : "Sunil",
"ApplicantName" : "Sunil Kumar Yadav"
},
"CreditDetail" : {
"ApplicantName" : "Test",
"DOB" : "03-08-2021",
"FatherName" : "Test",
"Gender" : "Male",
"UniqueIDCode" : "Pan Number",
"EmailID" : "asda#gmail.com",
"DocList" : {
"listofdocs" : {
"DocumentName" : "abc.jpg",
"DocumentPath" : "base64"
}
}
}, "DrugTestPanelCheck" : {
"DrugTestPanel" : "DrugTestPanel5",
"ApplicantName" : "Test Candidate"
},
"GDCDetails" : {
"ApplicantName" : "Sunil Kumar Yadav",
"DOB" : "03-08-2021",
"FatherName" : "Sunil"
},
"PassportCheckDetails" : {
"NameInPassport" : "Sunil Kumar Yadav",
"PassportNo" : "1231231",
"MachineReadableZone" : "",
"CandidateFirstName" : "Sunil",
"CandidateLastName" : "Yadav",
"DOB" : "03-08-2021",
"FatherName" : "Sunil",
"DocList" : {
"listofdocs" : {
"DocumentName" : "abc.jpg",
"DocumentPath" : "base64"
}
}
}
}
Really need some help on this.
Thanks

In order to determine which XML elements can occur with cardinality 0..*, you look only at the actual cardinality in the payload by testing whether count(*[name()=$childName]) > 1. By this, you miss the fact that the <EducationList> is allowed to contain more than one <Education> (even if it contains only one in this particular payload instance).
A clean solution would require you to look at the XML schema (in the WSDL document, probably). But in this case, the following heuristics might suffice: If an element name ends with List, it contains children with cardinality 0..*. Therefore, replace the test count(*[name()=$childName]) > 1 with
substring(name(), string-length(name()) - 3, 4) = 'List'

With the YAML processor mikefarah/yq, you can convert XML to JSON and make some custom adoptions to the conversion:
yq --input-format xml --output-format json '
with(.root;
.AddressHistory.Address |= select(type == "!!map") |= [.] |
.EducationList.Education |= select(type == "!!map") |= [.] |
.EmploymentList.Employment |= select(type == "!!map") |= [.] |
.AddressReferencesList.ListofReferences |= select(type == "!!map") |= [.] |
.PVWDetails.AddressList.Address |= select(type == "!!map") |= [.]
)
' input.xml
For given paths the update operator |= wraps an object (select(type == "!!map")) into an array ([.]).
Add all elements that should be an array to the code.
With kislyuk/xq, you can solve it this way:
ARRAY_PATHS='
[
"root.AddressHistory.Address",
"root.EducationList.Education",
"root.EmploymentList.Employment",
"root.AddressReferencesList.ListofReferences",
"root.PVWDetails.AddressList.Address"
]
'
xq --argjson paths "$ARRAY_PATHS" '
. as $input
| reduce ($paths
| map(split(".") # split given paths by "."
| . as $p
| select($input | getpath($p) | type == "object")))[] # process only objects at the given paths (ignore arrays)
as $path
(.; setpath($path; [getpath($path)])) # wrap objects at the given paths in an array
' input.xml
All given paths are checked if the value is an object: select($input | getpath($p) | type == "object").
Objects are wrapped into an array setpath($path; [getpath($path)]).
This solution is more generic and failsafe, if a given path is missing in the input.
Output (both versions)
{
"root": {
"ClientID": "1",
"PackageID": "650",
"SBUID": "2187",
"CandidateID": "456",
"AssociateId": "789",
"FirstName": "Meghana",
"MiddleName": null,
"LastName": "Rao",
"FatherName": "Satish",
"ContactNo": "7530001169",
"EmailID": "dummy#sap.com",
"AddressHistory": {
"Address": [
{
"SequenceNo": "0",
"AddressLine": "Kharghar,navi mumbai",
"City": "Maharashtra-Mumbai",
"State": "Maharashtra",
"PinCode": "410210",
"Country": "India",
"Landmark": null,
"StayFrom": "01-08-2013",
"StayTo": "06-08-2021",
"IsCurrentAddress": "false",
"IsPermanentAddress": "false",
"HouseNo": null,
"AddressType": "Current",
"DocList": {
"listofdocs": {
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
}
}
]
},
"EducationList": {
"Education": [
{
"SequenceNo": "0",
"Qualification": null,
"Degree": "Under Graduate Degree",
"CollegeName": "Amrutvahini College of engineering, Sangamner (Pune University)",
"Location": null,
"RollNumber": "123123",
"UniversityName": "Mumbai University",
"UniversityAddress": null,
"PeriodFrom": null,
"PeriodTo": null,
"YearOfPassing": "2014",
"Zipcode": null,
"Percentage": null,
"AdditionalRemarks": "10th/12th/Undergrad etc",
"International": "false",
"Country": null,
"DocList": {
"listofdocs": {
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
}
}
]
},
"EmploymentList": {
"Employment": [
{
"SequenceNo": "0",
"EmployerName": "Stravis Solutions",
"EmployerAddress": "Bangalore",
"EmployerContactNo": null,
"Designation": "SDE",
"EmployeeID": "asdas",
"FixedSalary": "0",
"IsCurrentEmployment": "false",
"RelievingDate": "15-10-2021",
"State": null,
"City": null,
"Zipcode": null,
"International": "false",
"Country": null,
"PFNumber": null,
"UANNumber": null,
"DocList": {
"listofdocs": {
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
},
"DateOfJoining": "18-03-2015"
},
{
"SequenceNo": "0",
"EmployerName": "Stravis Solutions",
"EmployerAddress": "Bangalore",
"EmployerContactNo": null,
"Designation": "SDE",
"EmployeeID": "asdas",
"FixedSalary": "0",
"IsCurrentEmployment": "false",
"RelievingDate": "15-10-2021",
"International": "false",
"Country": null,
"PFNumber": null,
"UANNumber": null,
"DocList": {
"listofdocs": {
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
},
"DateOfJoining": "18-03-2015"
}
]
},
"AddressReferencesList": {
"ListofReferences": [
{
"OrganizationName": "Com 1",
"AdditionalRemarks": null,
"NameOfReferee": "Ref1",
"RefereeOccupation": "SDE",
"RefereePhoneNumber": "123456",
"RefereeEmailAddress": "Ref1#com1.com"
},
{
"OrganizationName": "Com 1",
"AdditionalRemarks": null,
"NameOfReferee": "Ref1",
"RefereeOccupation": "SDE",
"RefereePhoneNumber": "123456",
"RefereeEmailAddress": "Ref1#com1.com"
}
]
},
"DOB": "03-08-2021",
"DLDetails": {
"DOB": "03-08-2021",
"ApplicantName": "Test",
"FatherName": "Test",
"dl_remarks": null,
"UniqueIDCode": "1231231",
"DocList": {
"listofdocs": {
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
}
},
"PanDetails": {
"DOB": "03-08-2021",
"ApplicantName": "Sunil Kumar Yadav",
"FatherName": "Sunil",
"pan_remarks": null,
"UniqueIDCode": "23123131",
"DocList": {
"listofdocs": {
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
}
},
"PVWDetails": {
"AddressList": {
"Address": [
{
"SequenceNo": "0",
"AddressLine": "Kharghar,navi mumbai",
"City": "Maharashtra-Mumbai",
"State": "Maharashtra",
"PinCode": "410210",
"Country": "India",
"Landmark": null,
"StayFrom": "01-08-2013",
"StayTo": "06-08-2021",
"IsCurrentAddress": "false",
"IsPermanentAddress": "false",
"HouseNo": "Sai shradha CHS.Sector-11,",
"AddressType": "Current",
"DocList": {
"listofdocs": {
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
}
}
]
},
"DOB": "03-08-2021",
"FatherName": "Sunil",
"ApplicantName": "Sunil Kumar Yadav"
},
"CreditDetail": {
"ApplicantName": "Test",
"DOB": "03-08-2021",
"FatherName": "Test",
"Gender": "Male",
"UniqueIDCode": "Pan Number",
"EmailID": "asda#gmail.com",
"DocList": {
"listofdocs": {
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
}
},
"DrugTestPanelCheck": {
"DrugTestPanel": "DrugTestPanel5",
"ApplicantName": "Test Candidate"
},
"GDCDetails": {
"ApplicantName": "Sunil Kumar Yadav",
"DOB": "03-08-2021",
"FatherName": "Sunil"
},
"PassportCheckDetails": {
"NameInPassport": "Sunil Kumar Yadav",
"PassportNo": "1231231",
"MachineReadableZone": null,
"CandidateFirstName": "Sunil",
"CandidateLastName": "Yadav",
"DOB": "03-08-2021",
"FatherName": "Sunil",
"DocList": {
"listofdocs": {
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
}
}
}
}

The standard xml-to-json XSLT 3.0 function can meet your requirement. The complexity lies in establishing the transform rules for when to use JSON maps and arrays.
I inferred the transform rules from the supplied input XML and output JSON. These rules may need adjustment to cover cases not tested by your sample. Here's the main xsl:template instruction:
<xsl:template match="*[*]" mode="outer">
<xsl:param name="key" as="xs:string?"/>
<xsl:variable name="distinctChildNames" as="xs:string*" select="*!name() => distinct-values()"/>
<xsl:choose>
<xsl:when test="count($distinctChildNames) gt 1 and exists($key)">
<array>
<xsl:sequence select="fn:keyAttribute(name())"/>
<map>
<xsl:apply-templates select="*" mode="outer">
<xsl:with-param name="key" select="name()"/>
</xsl:apply-templates>
</map>
</array>
</xsl:when>
<xsl:when test="count(*) gt 1 and count($distinctChildNames) eq 1">
<map>
<xsl:sequence select="fn:keyAttribute(name())"/>
<array key="{name(*[1])}">
<xsl:for-each select="*">
<map>
<xsl:apply-templates select="*" mode="outer"/>
</map>
</xsl:for-each>
</array>
</map>
</xsl:when>
<xsl:otherwise>
<map>
<xsl:sequence select="fn:keyAttribute(name())"/>
<xsl:apply-templates select="*" mode="outer">
<xsl:with-param name="key" select="name()"/>
</xsl:apply-templates>
</map>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
The JSON output:
{
"ClientID": "1",
"PackageID": "650",
"SBUID": "2187",
"CandidateID": "456",
"AssociateId": "789",
"FirstName": "Meghana",
"MiddleName": "",
"LastName": "Rao",
"FatherName": "Satish",
"ContactNo": "7530001169",
"EmailID": "dummy#sap.com",
"AddressHistory": {
"Address": [
{
"SequenceNo": "0",
"AddressLine": "Kharghar,navi mumbai",
"City": "Maharashtra-Mumbai",
"State": "Maharashtra",
"PinCode": "410210",
"Country": "India",
"Landmark": "",
"StayFrom": "01-08-2013",
"StayTo": "06-08-2021",
"IsCurrentAddress": false,
"IsPermanentAddress": false,
"HouseNo": "",
"AddressType": "Current",
"DocList": {
"listofdocs": [
{
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
]
}
}
]
},
"EducationList": {
"Education": [
{
"SequenceNo": "0",
"Qualification": "",
"Degree": "Under Graduate Degree",
"CollegeName": "Amrutvahini College of engineering, Sangamner (Pune University)",
"Location": "",
"RollNumber": "123123",
"UniversityName": "Mumbai University",
"UniversityAddress": "",
"PeriodFrom": "",
"PeriodTo": "",
"YearOfPassing": "2014",
"Zipcode": "",
"Percentage": "",
"AdditionalRemarks": "10th\/12th\/Undergrad etc",
"International": false,
"Country": "",
"DocList": {
"listofdocs": [
{
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
]
}
}
]
},
"EmploymentList": {
"Employment": [
{
"SequenceNo": "0",
"EmployerName": "Stravis Solutions",
"EmployerAddress": "Bangalore",
"EmployerContactNo": "",
"Designation": "SDE",
"EmployeeID": "asdas",
"FixedSalary": "0",
"IsCurrentEmployment": false,
"RelievingDate": "15-10-2021",
"State": "",
"City": "",
"Zipcode": "",
"International": false,
"Country": "",
"PFNumber": "",
"UANNumber": "",
"DocList": {
"listofdocs": [
{
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
]
},
"DateOfJoining": "18-03-2015"
},
{
"SequenceNo": "0",
"EmployerName": "Stravis Solutions",
"EmployerAddress": "Bangalore",
"EmployerContactNo": "",
"Designation": "SDE",
"EmployeeID": "asdas",
"FixedSalary": "0",
"IsCurrentEmployment": false,
"RelievingDate": "15-10-2021",
"International": false,
"Country": "",
"PFNumber": "",
"UANNumber": "",
"DocList": {
"listofdocs": [
{
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
]
},
"DateOfJoining": "18-03-2015"
}
]
},
"AddressReferencesList": {
"ListofReferences": [
{
"OrganizationName": "Com 1",
"AdditionalRemarks": "",
"NameOfReferee": "Ref1",
"RefereeOccupation": "SDE",
"RefereePhoneNumber": "123456",
"RefereeEmailAddress": "Ref1#com1.com"
},
{
"OrganizationName": "Com 1",
"AdditionalRemarks": "",
"NameOfReferee": "Ref1",
"RefereeOccupation": "SDE",
"RefereePhoneNumber": "123456",
"RefereeEmailAddress": "Ref1#com1.com"
}
]
},
"DOB": "03-08-2021",
"DLDetails": {
"DOB": "03-08-2021",
"ApplicantName": "Test",
"FatherName": "Test",
"dl_remarks": "",
"UniqueIDCode": "1231231",
"DocList": {
"listofdocs": [
{
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
]
}
},
"PanDetails": {
"DOB": "03-08-2021",
"ApplicantName": "Sunil Kumar Yadav",
"FatherName": "Sunil",
"pan_remarks": "",
"UniqueIDCode": "23123131",
"DocList": {
"listofdocs": [
{
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
]
}
},
"PVWDetails": {
"AddressList": {
"Address": [
{
"SequenceNo": "0",
"AddressLine": "Kharghar,navi mumbai",
"City": "Maharashtra-Mumbai",
"State": "Maharashtra",
"PinCode": "410210",
"Country": "India",
"Landmark": "",
"StayFrom": "01-08-2013",
"StayTo": "06-08-2021",
"IsCurrentAddress": false,
"IsPermanentAddress": false,
"HouseNo": "Sai shradha CHS.Sector-11,",
"AddressType": "Current",
"DocList": {
"listofdocs": [
{
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
]
}
}
]
},
"DOB": "03-08-2021",
"FatherName": "Sunil",
"ApplicantName": "Sunil Kumar Yadav"
},
"CreditDetail": {
"ApplicantName": "Test",
"DOB": "03-08-2021",
"FatherName": "Test",
"Gender": "Male",
"UniqueIDCode": "Pan Number",
"EmailID": "asda#gmail.com",
"DocList": {
"listofdocs": [
{
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
]
}
},
"DrugTestPanelCheck": {
"DrugTestPanel": "DrugTestPanel5",
"ApplicantName": "Test Candidate"
},
"GDCDetails": {
"ApplicantName": "Sunil Kumar Yadav",
"DOB": "03-08-2021",
"FatherName": "Sunil"
},
"PassportCheckDetails": {
"NameInPassport": "Sunil Kumar Yadav",
"PassportNo": "1231231",
"MachineReadableZone": "",
"CandidateFirstName": "Sunil",
"CandidateLastName": "Yadav",
"DOB": "03-08-2021",
"FatherName": "Sunil",
"DocList": {
"listofdocs": [
{
"DocumentName": "abc.jpg",
"DocumentPath": "base64"
}
]
}
}
}
There are minor differences in the result:
The '/' character is escaped to \/ in the JSON output
JSON properties transformed from empty XML elements: the XSLT here always keeps the property and sets the value to an empty string
Here's the full XSLT used:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="com.example.functions"
xmlns="http://www.w3.org/2005/xpath-functions"
expand-text="yes"
version="3.0">
<xsl:output method="text" indent="yes"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:mode name="outer" on-no-match="shallow-copy"/>
<xsl:template match="/*">
<xsl:variable name="result" as="node()*">
<map>
<xsl:apply-templates select="*" mode="outer"/>
</map>
</xsl:variable>
<xsl:sequence select="xml-to-json($result)"/>
</xsl:template>
<xsl:template match="*[*]" mode="outer">
<xsl:param name="key" as="xs:string?"/>
<xsl:variable name="distinctChildNames" as="xs:string*" select="*!name() => distinct-values()"/>
<xsl:choose>
<xsl:when test="count($distinctChildNames) gt 1 and exists($key)">
<array>
<xsl:sequence select="fn:keyAttribute(name())"/>
<map>
<xsl:apply-templates select="*" mode="outer">
<xsl:with-param name="key" select="name()"/>
</xsl:apply-templates>
</map>
</array>
</xsl:when>
<xsl:when test="count(*) gt 1 and count($distinctChildNames) eq 1">
<map>
<xsl:sequence select="fn:keyAttribute(name())"/>
<array key="{name(*[1])}">
<xsl:for-each select="*">
<map>
<xsl:apply-templates select="*" mode="outer"/>
</map>
</xsl:for-each>
</array>
</map>
</xsl:when>
<xsl:otherwise>
<map>
<xsl:sequence select="fn:keyAttribute(name())"/>
<xsl:apply-templates select="*" mode="outer">
<xsl:with-param name="key" select="name()"/>
</xsl:apply-templates>
</map>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="*[empty(*) and exists(text())]" mode="outer">
<xsl:apply-templates select="node()" mode="outer">
<xsl:with-param name="key" select="name()"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="*[empty(*) and empty(text())]" mode="outer">
<string key="{name()}"/>
</xsl:template>
<xsl:template match="text()[. = ('true', 'false')]" mode="outer">
<xsl:param name="key" as="xs:string?"/>
<boolean key="{$key}">{.}</boolean>
</xsl:template>
<xsl:template match="text()" mode="outer">
<xsl:param name="key" as="xs:string?"/>
<xsl:if test="exists($key)">
<string key="{$key}">{.}</string>
</xsl:if>
</xsl:template>
<xsl:function name="fn:keyAttribute" as="attribute()?">
<xsl:param name="key" as="xs:string?"/>
<xsl:if test="$key">
<xsl:attribute name="key" select="$key"/>
</xsl:if>
</xsl:function>
</xsl:stylesheet>

Related

Displaying artist data from network response via Spotify API

Here is my Code.
spotifyApi.getMyCurrentPlaybackState()
.then((response) => {
this.setState({
nowPlaying: {
name: response.item.name,
artist: response.item.artists.name,
albumArt: response.item.album.images[0].url
}
});
})
my response object for 'artist:' is not displaying the artists' name. How can I change
artist: response.item.artists.name,
to get "Key Glock" to display?
Here is the network response data.
"item" : {
"album" : {
"album_type" : "album",
"artists" : [ {
"external_urls" : {
"spotify" : "https://open.spotify.com/artist/0RESbWvOMyua0yuyVrztJ5"
},
"href" : "https://api.spotify.com/v1/artists/0RESbWvOMyua0yuyVrztJ5",
"id" : "0RESbWvOMyua0yuyVrztJ5",
"name" : "Key Glock",
"type" : "artist",
"uri" : "spotify:artist:0RESbWvOMyua0yuyVrztJ5"
} ],
"available_markets" : [ "AD", "AE", "AG", "AL", "AM", "AO", "AR", "AT", "AU", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BN", "BO", "BR", "BS", "BT", "BW", "BY", "BZ", "CA", "CD", "CG", "CH", "CI", "CL", "CM", "CO", "CR", "CV", "CW", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "ES", "FI", "FJ", "FM", "FR", "GA", "GB", "GD", "GE", "GH", "GM", "GN", "GQ", "GR", "GT", "GW", "GY", "HK", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IN", "IQ", "IS", "IT", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KR", "KW", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MG", "MH", "MK", "ML", "MN", "MO", "MR", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NE", "NG", "NI", "NL", "NO", "NP", "NR", "NZ", "OM", "PA", "PE", "PG", "PH", "PK", "PL", "PS", "PT", "PW", "PY", "QA", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SE", "SG", "SI", "SK", "SL", "SM", "SN", "SR", "ST", "SV", "SZ", "TD", "TG", "TH", "TJ", "TL", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "US", "UY", "UZ", "VC", "VE", "VN", "VU", "WS", "XK", "ZA", "ZM", "ZW" ],
"external_urls" : {
"spotify" : "https://open.spotify.com/album/7snqOEQEtKqxJw3NTGml6i"
artists is an array, presumably the spotify API would return multiple artists if you had two or more artists on a track, which we would normally write "Jim feat. John".
To get the first artist's name: response.item.album.artists[0].name
To get all the artists' names: response.item.album.artists.map(curr => curr.name)

How can I correct this Jolt Transformation?

This is an input that needs to be transformed using Jolt Transformation to obtain the expected output.
I am trying to write a jolt transformation for the below input.
but It's not matched with the expected output.
My Input:
{
"ConsolidatedList": [
{
"AliasType": "AKA",
"AliasTypeName": "AKA",
"BusinessRegNumber": {
"nil": null
},
"nil": null,
"Country": null,
"CountryOfBirth": "Syria",
"CurrentOwners": {
"nil": null
},
"DateListed": "2021-03-15T00:00:00",
"DateListedDay": 15,
"DateListedMonth": 3,
"DateListedYear": 2021,
"DateOfBirth": "01/09/1975",
"DateOfBirthId": 4751,
"DayOfBirth": 1,
"EmailAddress": {
"nil": null
},
"FCOId": "SYR0377",
"FlagOfVessel": {
"nil": null
},
"FullAddress": null,
"FullName": " Al Shebil Luna ",
"FurtherIdentifiyingInformation": {
"nil": null
},
"Gender": "Female",
"GroupID": 14070,
"GroupStatus": "Asset Freeze Targets",
"GroupTypeDescription": "Individual",
"GrpStatus": "A",
"HIN": {
"nil": null
},
"ID": 33233,
"IMONumber": {
"nil": null
},
"LastUpdated": "2021-03-15T00:00:00",
"LastUpdatedDay": 15,
"LastUpdatedMonth": 3,
"LastUpdatedYear": 2021,
"LengthOfVessel": {
"nil": null
},
"ListingType": "UK autonomous",
"MonthOfBirth": 9,
"Name6": "Al Shebil",
"NameTitle": null,
"NationalIdNumber": {
"nil": null
},
"Nationality": "Syria",
"OrgType": {
"nil": null
},
"OtherInformation": "MapRecord[{{http://www.w3.org/2001/XMLSchema-instance}nil=true}]",
"ParentCompany": {
"nil": null
},
"PassportDetails": "MapRecord[{{http://www.w3.org/2001/XMLSchema-instance}nil=true}]",
"PhoneNumber": {
"nil": null
},
"Position": "Media Adviser to President Assad",
"PostCode": null,
"PreviousFlags": {
"nil": null
},
"PreviousOwners": {
"nil": null
},
"RegimeName": "Syria",
"Subsidiaries": {
"nil": null
},
"TonnageOfVessel": {
"nil": null
},
"TownOfBirth": "Suweida",
"TypeOfVessel": {
"nil": null
},
"UKStatementOfReasons": "Adviser to President Assad and a prominent member of his inner circle. As Media Adviser to the President she supports the Syrian regime, which relies on disinformation and a lack of media freedom to repress the civilian population. She is also associated with the Syrian regime through her role as an adviser.\n",
"Website": {
"nil": null
},
"YearBuilt": {
"nil": null
},
"YearOfBirth": 1975,
"address1": null,
"address2": null,
"address3": null,
"address4": null,
"address5": null,
"address6": null,
"name1": "Luna",
"name2": null,
"name3": null,
"name4": null,
"name5": null
},
{
"AliasType": "AKA",
"AliasTypeName": "AKA",
"BusinessRegNumber": {
"nil": null
},
"nil": null,
"Country": null,
"CountryOfBirth": "Syria",
"CurrentOwners": {
"nil": null
},
"DateListed": "2021-03-15T00:00:00",
"DateListedDay": 15,
"DateListedMonth": 3,
"DateListedYear": 2021,
"DateOfBirth": "01/09/1975",
"DateOfBirthId": 4751,
"DayOfBirth": 1,
"EmailAddress": {
"nil": null
},
"FCOId": "SYR0377",
"FlagOfVessel": {
"nil": null
},
"FullAddress": null,
"FullName": " Al Shebil Luna ",
"FurtherIdentifiyingInformation": {
"nil": null
},
"Gender": "Female",
"GroupID": 14070,
"GroupStatus": "Asset Freeze Targets",
"GroupTypeDescription": "Individual",
"GrpStatus": "A",
"HIN": {
"nil": null
},
"ID": 33233,
"IMONumber": {
"nil": null
},
"LastUpdated": "2021-03-15T00:00:00",
"LastUpdatedDay": 15,
"LastUpdatedMonth": 3,
"LastUpdatedYear": 2021,
"LengthOfVessel": {
"nil": null
},
"ListingType": "UK autonomous",
"MonthOfBirth": 9,
"Name6": "Al Shebil",
"NameTitle": null,
"NationalIdNumber": {
"nil": null
},
"Nationality": "Syria",
"OrgType": {
"nil": null
},
"OtherInformation": "MapRecord[{{http://www.w3.org/2001/XMLSchema-instance}nil=true}]",
"ParentCompany": {
"nil": null
},
"PassportDetails": "MapRecord[{{http://www.w3.org/2001/XMLSchema-instance}nil=true}]",
"PhoneNumber": {
"nil": null
},
"Position": "Media Adviser to President Assad",
"PostCode": null,
"PreviousFlags": {
"nil": null
},
"PreviousOwners": {
"nil": null
},
"RegimeName": "Syria",
"Subsidiaries": {
"nil": null
},
"TonnageOfVessel": {
"nil": null
},
"TownOfBirth": "Suweida",
"TypeOfVessel": {
"nil": null
},
"UKStatementOfReasons": "Adviser to President Assad and a prominent member of his inner circle. As Media Adviser to the President she supports the Syrian regime, which relies on disinformation and a lack of media freedom to repress the civilian population. She is also associated with the Syrian regime through her role as an adviser.\n",
"Website": {
"nil": null
},
"YearBuilt": {
"nil": null
},
"YearOfBirth": 1975,
"address1": null,
"address2": null,
"address3": null,
"address4": null,
"address5": null,
"address6": null,
"name1": "Hassan",
"name2": "Muh",
"name3": "Cane",
"name4": null,
"name5": null
}
]
}
And the expected output is -
{
"Count": "2", // Counter for the number of records
"LastUpdated": "08/03/2020 12:00:00",
"RecordType": [
"Entity",
"Individual",
"Vessel"
],
"Pages": "1",
"Records": [
{
"_id": "1", // Counter
"AdditionalInformation": "Other Information: (UK Sanctions List Ref):AQD0081 (UN Ref):QDe.014 (Further Identifiying Information):Headed by Abdelmalek Droukdel (QDi.232).Zone of operation includes Algeria and parts of Mali, Mauritania, Niger, Tunisia and Morocco.Review pursuant to Security Council resolution 1822 (2008) was concluded on 21 Jun.2010.INTERPOL-UN Security Council Special Notice web link: https://www.interpol.int/en/notice/search/une/5278467; Listed On: 10/10/2001; Last Updated: 12/31/2020; Group ID: 7247",
"RecordType": "Entity",
"Names": [
{
"_id": "1", //counter
"OtherName": "THE ORGANIZATION OF AL-QAIDA IN THE ISLAMIC MAGHREB",
"UnparsedName": "",
"FirstName": "",
"LastName": "",
"NameType": "Primary"
},
{
"_id": "2",
"OtherName": "AL QAIDA AU MAGHREB ISLAMIQUE (AQMI)",
"UnparsedName": "",
"FirstName": "",
"LastName": "",
"NameType": "Alias"
},
{
"_id": "3",
"OtherName": "AQIM",
"UnparsedName": "",
"FirstName": "",
"LastName": "",
"NameType": "Alias"
},
{
"_id": "4",
"OtherName": "LE GROUPE SALAFISTE POUR LA PREDICATION ET LE COMBAT (GSPC)",
"UnparsedName": "",
"FirstName": "",
"LastName": "",
"NameType": "Formerly Known As"
},
{
"_id": "5",
"OtherName": "SALAFIST GROUP FOR CALL AND COMBAT",
"UnparsedName": "",
"FirstName": "",
"LastName": "",
"NameType": "Formerly Known As"
}
],
"Addresses": [
{
"_id": "1",
"PostalCode": "",
"Street": "",
"City": "",
"StateProvince": "",
"Country": {
"Name": "Algeria",
"RelationType": "Address"
}
},
{
"_id": "2",
"PostalCode": "",
"Street": "",
"City": "",
"StateProvince": "",
"Country": {
"Name": "Mali",
"RelationType": "Address"
}
},
{
"_id": "3",
"PostalCode": "",
"Street": "",
"City": "",
"StateProvince": "",
"Country": {
"Name": "Mauritania",
"RelationType": "Address"
}
},
{
"_id": "4",
"PostalCode": "",
"Street": "",
"City": "",
"StateProvince": "",
"Country": {
"Name": "Morocco",
"RelationType": "Address"
}
},
{
"_id": "5",
"PostalCode": "",
"Street": "",
"City": "",
"StateProvince": "",
"Country": {
"Name": "Niger",
"RelationType": "Address"
}
},
{
"_id": "6",
"PostalCode": "",
"Street": "",
"City": "",
"StateProvince": "",
"Country": {
"Name": "Tunisia",
"RelationType": "Address"
}
}
],
"Sanctions": [
{
"_id": "1",
"Sanction": "HM Treasury Al-Qaida Sanction",
"ExpirationDate": "",
"SanctionDate": ""
}
]
},
{
"_id": "2",
"AdditionalInformation": "Other Information: (UK Sanctions List Ref):AFG0110 (UN Ref): TAi.142 (Further Identifiying Information):Review pursuant to Security Council resolution 1822 (2008) was concluded on 29 Jul. 2010. INTERPOL-UN Security Council Special Notice web link: https://www.interpol.int/en/How-we-work/Notices/View-UN-Notices-Individuals click here.; Listed On: 02/23/2001; Last Updated: 2/1/2021; Group ID: 6895",
"RecordType": "Person",
"Names": [
{
"_id": "1",
"OtherName": "",
"UnparsedName": "",
"FirstName": "Abdul Hai Hazem",
"LastName": "ABDUL QADER",
"NameType": "Primary"
},
{
"_id": "2",
"OtherName": "",
"UnparsedName": "",
"FirstName": "Abdul Hai",
"LastName": "HAZEM",
"NameType": "Alias"
}
],
"Identifiers": [
{
"_id": "1",
"IDValue": "1971",
"IDType": "Date Of Birth"
},
{
"_id": "2",
"IDValue": "Pashawal Yargatoo village, Andar District, Ghazni Province, Afghanistan",
"IDType": "Place Of Birth"
},
{
"_id": "3",
"IDValue": "D 0001203 (Afghan)",
"IDType": "Passport"
}
],
"Addresses": [
{
"_id": "1",
"PostalCode": "",
"Street": "",
"City": "",
"StateProvince": "Kabul Province",
"Country": {
"Name": "Afghanistan",
"RelationType": "Address"
}
},
{
"_id": "2",
"PostalCode": "",
"Street": "",
"City": "Kabul City",
"StateProvince": "Kabul Province",
"Country": {
"Name": "",
"RelationType": "Address"
}
},
{
"_id": "3",
"PostalCode": "",
"Street": "",
"City": "",
"StateProvince": "",
"Country": {
"Name": "Afghan",
"RelationType": "Nationality"
}
}
],
"Sanctions": [
{
"_id": "1",
"Sanction": "HM Treasury Afghanistan Sanction",
"ExpirationDate": "",
"SanctionDate": ""
}
]
}
]
}
My spec is -
[
{
"operation" : "shift",
"spec": {
"ConsolidatedList": {
"*": {
"GroupTypeDescription": "RecordType",
"LastUpdated": "LastUpdated",
"UKStatementOfReasons": "Records.AdditionalInformation",
"Name6": "Records.Names.[&1].Other Name",
"name3": "Records.Names.[&1].UnparsedName",
"name1": "Records.Names.[&1].FirstName",
"name2": "Records.Names.[&1].LastName",
"AliasType": "Records.Names.[&1].NameType",
"PostCode": "Records.Address.[&1].PostalCode",
"address2": "Records.Address.[&1].Street",
"address6": "Records.Address.[&1].City",
"Country": "Records.Address.[&1].StateProvince",
"CountryOfBirth": "Records.Address.[&1].Country.Name"
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec" : {
"Count": "size(1,Records)",
"Pages": "1"
}
}
]
The spec is not transforming as expected output.

How to create a JSON structure in ReactJS

I have a use-case to create a JSON structure in React in order to POST an API request. The JSON structure body contains objects and arrays.
Please let me know how to create it in ReactJS.
Below is the sample JSON structure that needs to be created using ReactJS:-
{
"transactionAmount": {
"currency": "INR",
"value": 1220.38
},
"transactionDate": "2020-05-18T00:00:00Z",
"tripData": {
"agencyBooked": false,
"legs": [
{
"endLocation": {
"countryCode": "IN",
"city": "Delhi",
"name": "Indira Gandhi International"
},
"startDate": "2020-05-22",
"startTime": "08:00",
"returnLeg": false,
"startLocation": {
"countryCode": "US",
"city": "San Francisco",
"name": "San Francisco International"
},
"endTime": "21:00",
"endDate": "2020-05-22",
"startLocationDetail": "none"
},
{
"endLocation": {
"countryCode": "US",
"city": "San Francisco",
"name": "San Francisco International"
},
"returnLeg": true,
"startDate": "2020-05-24",
"startLocation": {
"countryCode": "IN",
"city": "Delhi",
"name": "Indira Gandhi International"
},
"startTime": "17:00"
}
],
"segmentType": {
"category": "REQ_SEG_AIRFR",
"code": "AIRFR"
},
"selfBooked": false,
"tripType": "ROUND_TRIP"
}
}
You can simply make a JSON format like this.
const dummyObject = {
name: 'Dummy',
age: 22,
about: {
hobbies: ['soccer']
},
works: true
}

JSON to SQL Server 2016 missing rows from array

I am new to getting JSON into SQL Server 2016, I thought I had it down, but I notice that I am missing some details from the array, looking at the image, there are four address', but I saw there are some more address' missing for example Burrows Rd, and Urana RD. How can I make sure that all the address' captured?
https://i.stack.imgur.com/erzBV.jpg
#json nvarchar(max)
#json = N'{
"response": [
{
"application": {
"info": {
"dat_id": "010.2018.00036494.001",
"development_type": "Residential - Single new dwelling",
"application_type": "DA",
"last_modified_date": "2018-12-03T11:35:24+11:00",
"description": "Residence, Garage & Colorbond Shed, Demolition of Existing Residence & Tree Removal",
"authority": {
"ref": "http://gemini:82/ApplicationTracker/atdis/1.0",
"name": "AlburyCity"
},
"lodgement_date": "2018-10-26T00:00:00+11:00",
"determination_date": null,
"determination_type": "Pending",
"status": "In Progress",
"notification_start_date": null,
"notification_end_date": null,
"officer": "David Flood",
"estimated_cost": "Not applicable.",
"related_apps": [ ]
},
"reference": {
"more_info_url": "http://gemini:82/ApplicationTracker/Application/ApplicationDetails/010.2018.00036494.001/",
"comments_url": null
},
"locations": [
{
"land_title_ref": {
"torrens": {
"lot": "11",
"section": null,
"dpsp_id": "DP 1031272"
}
},
"address": {
"street": "680 Centaur RD",
"suburb": "HAMILTON VALLEY",
"state": "NSW",
"postcode": "2641"
},
"geometry": null
},
{
"land_title_ref": {
"torrens": {
"lot": "11",
"section": null,
"dpsp_id": "DP 1031272"
}
},
"address": {
"street": "Urana RD",
"suburb": "HAMILTON VALLEY",
"state": "NSW",
"postcode": "2641"
},
"geometry": null
},
{
"land_title_ref": {
"torrens": {
"lot": "11",
"section": null,
"dpsp_id": "DP 1031272"
}
},
"address": {
"street": "Burrows RD",
"suburb": "HAMILTON VALLEY",
"state": "NSW",
"postcode": "2641"
},
"geometry": null
}
],
"events": [
{
"id": "3680347",
"timestamp": "2018-11-01T15:58:00+11:00",
"description": "Public Notification",
"event_type": "PNOT",
"status": "COMP"
},
{
"id": "3680348",
"timestamp": "2018-11-01T15:58:00+11:00",
"description": "Referral Engineering",
"event_type": "ENG",
"status": "COMP"
},
{
"id": "3680349",
"timestamp": "2018-11-01T15:59:00+11:00",
"description": "Referal Parks & Recreation",
"event_type": "TREE",
"status": "COMP"
},
{
"id": "3680350",
"timestamp": "2018-11-01T16:00:00+11:00",
"description": "Acknowledgement to Applicant",
"event_type": "ACKN",
"status": "COMP"
},
{
"id": "3683617",
"timestamp": "2018-11-21T14:59:00+11:00",
"description": "Site Assessment Inspection",
"event_type": "SITE",
"status": "PASS"
},
{
"id": "3685155",
"timestamp": "2018-12-03T11:37:00+11:00",
"description": "Assessment Report",
"event_type": "ASS3",
"status": "COMP"
}
],
"documents": [
{
"ref": "DOC18/163129",
"title": "Statement of Environmental Effects - SEE",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=6hF7YEiv0qE=&fileName=Statement+of+Environmental+Effects+-+SEE.PDF"
},
{
"ref": "DOC18/163139",
"title": "Site Plan and Elevations",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=1Gv3GVOIHCM=&fileName=Site+Plan+and+Elevations.PDF"
}
],
"people": [
{
"name": "Karyn Ford",
"role": "Applicant",
"contact": "6023 8287"
}
],
"extended": {
"software_vendor": "Civica",
"software_vendor_url": "http://www.civica.com.au"
}
}
},
{
"application": {
"info": {
"dat_id": "017.2018.00036017.001",
"development_type": "Subdivision Only",
"application_type": "SCC",
"last_modified_date": "2018-12-03T10:19:25+11:00",
"description": "Roads, Sewer, Water & Drainage for Two (2) Lot Torrens Title Subdivisi on",
"authority": {
"ref": "http://gemini:82/ApplicationTracker/atdis/1.0",
"name": "AlburyCity"
},
"lodgement_date": "2018-11-14T00:00:00+11:00",
"determination_date": "2018-11-29T00:00:00+11:00",
"determination_type": "Approved under delegation",
"status": "Determined",
"notification_start_date": null,
"notification_end_date": null,
"officer": "Sharna Holland",
"estimated_cost": "Not applicable.",
"related_apps": [ "http://gemini:82/ApplicationTracker/atdis/1.0/010.2018.00036017.001.json" ]
},
"reference": {
"more_info_url": "http://gemini:82/ApplicationTracker/Application/ApplicationDetails/017.2018.00036017.001/",
"comments_url": null
},
"locations": [
{
"land_title_ref": {
"torrens": {
"lot": "A",
"section": null,
"dpsp_id": "DP 161410"
}
},
"address": {
"street": "419 Hovell ST",
"suburb": "SOUTH ALBURY",
"state": "NSW",
"postcode": "2640"
},
"geometry": null
},
{
"land_title_ref": {
"torrens": {
"lot": "A",
"section": null,
"dpsp_id": "DP 161410"
}
},
"address": {
"street": "Charles ST",
"suburb": "SOUTH ALBURY",
"state": "NSW",
"postcode": "2640"
},
"geometry": null
}
],
"events": [
{
"id": "3683888",
"timestamp": "2018-11-23T14:03:00+11:00",
"description": "Acknowledgement to Applicant",
"event_type": "ACKN",
"status": "COMP"
},
{
"id": "3683902",
"timestamp": "2018-11-23T15:21:00+11:00",
"description": "Referral Engineering",
"event_type": "ENG",
"status": "COMP"
},
{
"id": "3683903",
"timestamp": "2018-11-23T15:21:00+11:00",
"description": "Referral Building Surveyor 3",
"event_type": "BS3",
"status": "COMP"
},
{
"id": "3683904",
"timestamp": "2018-11-23T15:21:00+11:00",
"description": "Referral Trainee Town Planner",
"event_type": "TTP1",
"status": "COMP"
},
{
"id": "3684791",
"timestamp": "2018-11-29T14:36:00+11:00",
"description": "Collected Determination",
"event_type": "COLL",
"status": "COMP"
}
],
"documents": [
{
"ref": "DOC18/177392",
"title": "Subdivision Works Certificate",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=8qU1Pkawfvg=&fileName=Subdivision+Works+Certificate.PDF"
}
],
"people": [
{
"name": "Eslers Land Consulting",
"role": "Applicant",
"contact": "6021 1322"
}
],
"extended": {
"software_vendor": "Civica",
"software_vendor_url": "http://www.civica.com.au"
}
}
},
{
"application": {
"info": {
"dat_id": "010.2016.00034838.001",
"development_type": "Residential - New multi unit",
"application_type": "DA",
"last_modified_date": "2018-12-03T09:36:09+11:00",
"description": "Twenty (20) Detached Self Contained Residences - Kensington Gardens Retirement Village",
"authority": {
"ref": "http://gemini:82/ApplicationTracker/atdis/1.0",
"name": "AlburyCity"
},
"lodgement_date": "2016-08-17T00:00:00+10:00",
"determination_date": "2016-10-24T00:00:00+11:00",
"determination_type": "Approved under delegation",
"status": "Determined",
"notification_start_date": null,
"notification_end_date": null,
"officer": "Christopher Eldred",
"estimated_cost": "Not applicable.",
"related_apps": [ "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.001.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.002.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.003.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.004.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.005.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.006.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.007.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.008.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.009.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.010.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.011.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.012.json" ]
},
"reference": {
"more_info_url": "http://gemini:82/ApplicationTracker/Application/ApplicationDetails/010.2016.00034838.001/",
"comments_url": null
},
"locations": [
{
"land_title_ref": {
"torrens": {
"lot": "2",
"section": null,
"dpsp_id": "DP 874732"
}
},
"address": {
"street": "100 Table Top RD",
"suburb": "THURGOONA",
"state": "NSW",
"postcode": "2640"
},
"geometry": null
}
],
"events": [
{
"id": "3583145",
"timestamp": "2016-08-17T14:13:00+10:00",
"description": "Further Information Requested",
"event_type": "INFO",
"status": "COMP"
},
{
"id": "3573096",
"timestamp": "2016-08-18T15:34:00+10:00",
"description": "Public Notification",
"event_type": "PNOT",
"status": "COMP"
},
{
"id": "3573097",
"timestamp": "2016-08-18T15:37:00+10:00",
"description": "Referral Building Surveyor 2",
"event_type": "BS2",
"status": "COMP"
},
{
"id": "3573098",
"timestamp": "2016-08-18T15:37:00+10:00",
"description": "Referral Plumbing Inspector",
"event_type": "PI",
"status": "COMP"
},
{
"id": "3573099",
"timestamp": "2016-08-18T15:37:00+10:00",
"description": "Referral Engineering",
"event_type": "ENG",
"status": "COMP"
},
{
"id": "3573100",
"timestamp": "2016-08-18T15:38:00+10:00",
"description": "Referral Environmental Planner",
"event_type": "ENV",
"status": "COMP"
},
{
"id": "3573103",
"timestamp": "2016-08-18T15:43:43+10:00",
"description": "Acknowledgement to Applicant",
"event_type": "ACKN",
"status": "COMP"
},
{
"id": "3575194",
"timestamp": "2016-09-06T00:00:00+10:00",
"description": "Assessment Report",
"event_type": "ASS3",
"status": "COMP"
}
],
"documents": [
{
"ref": "DOC16/209893",
"title": "Statement of Environmental Effects - SEE",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=sQkVV9rEsTU=&fileName=Statement+of+Environmental+Effects+-+SEE.PDF"
},
{
"ref": "DOC16/209896",
"title": "Site Plan & Elevations",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=3dRqEZHzGeo=&fileName=Site+Plan+%26+Elevations.PDF"
},
{
"ref": "DOC16/211819",
"title": "Assessment Report",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=DVTQkQQqbns=&fileName=Assessment+Report.PDF"
},
{
"ref": "DOC16/240764",
"title": "Development Consent",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=TY+Y3zjyDKw=&fileName=Development+Consent.PDF"
}
],
"people": [
{
"name": "Kensington Gardens Lifestyle Estates",
"role": "Applicant",
"contact": "6049 3100"
}
],
"extended": {
"software_vendor": "Civica",
"software_vendor_url": "http://www.civica.com.au"
}
}
},
{
"application": {
"info": {
"dat_id": "010.2018.00036468.001",
"development_type": "Residential - Single new dwelling",
"application_type": "DA",
"last_modified_date": "2018-11-30T17:17:25+11:00",
"description": "Residence, Garage and Retaining Walls",
"authority": {
"ref": "http://gemini:82/ApplicationTracker/atdis/1.0",
"name": "AlburyCity"
},
"lodgement_date": "2018-10-19T00:00:00+11:00",
"determination_date": "2018-11-26T00:00:00+11:00",
"determination_type": "Approved under delegation",
"status": "Determined",
"notification_start_date": null,
"notification_end_date": null,
"officer": "David Flood",
"estimated_cost": "Not applicable.",
"related_apps": [ "http://gemini:82/ApplicationTracker/atdis/1.0/011.2018.00036468.001.json" ]
},
"reference": {
"more_info_url": "http://gemini:82/ApplicationTracker/Application/ApplicationDetails/010.2018.00036468.001/",
"comments_url": null
},
"locations": [
{
"land_title_ref": {
"torrens": {
"lot": "218",
"section": null,
"dpsp_id": "DP 1228226"
}
},
"address": {
"street": "20 Stockman CRCT",
"suburb": "THURGOONA",
"state": "NSW",
"postcode": "2640"
},
"geometry": null
}
],
"events": [
{
"id": "3678966",
"timestamp": "2018-10-25T10:47:00+11:00",
"description": "Public Notification",
"event_type": "PNOT",
"status": "COMP"
},
{
"id": "3678967",
"timestamp": "2018-10-25T10:48:00+11:00",
"description": "Referral Engineering",
"event_type": "ENG",
"status": "COMP"
},
{
"id": "3678974",
"timestamp": "2018-10-25T10:51:00+11:00",
"description": "Acknowledgement to Applicant",
"event_type": "ACKN",
"status": "COMP"
},
{
"id": "3681955",
"timestamp": "2018-11-01T15:49:00+11:00",
"description": "Site Assessment Inspection",
"event_type": "SITE",
"status": "COMP"
},
{
"id": "3684251",
"timestamp": "2018-11-27T10:24:00+11:00",
"description": "Collected Determination",
"event_type": "COLL",
"status": "COMP"
}
],
"documents": [
{
"ref": "DOC18/159026",
"title": "Statement of Environmental Effects - SEE",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=MaiWkTs8V+g=&fileName=Statement+of+Environmental+Effects+-+SEE.PDF"
},
{
"ref": "DOC18/159033",
"title": "Site Plan and Elevations and Superseded Plan",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=2xpqra8gNb0=&fileName=Site+Plan+and+Elevations+and+Superseded+Plan.PDF"
},
{
"ref": "DOC18/162569",
"title": "Assessment Report - Bldg Residential",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=bKYCMP01aJE=&fileName=Assessment+Report+-+Bldg+Residential.PDF"
},
{
"ref": "DOC18/168584",
"title": "Development Consent",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=SxGG/yKi68s=&fileName=Development+Consent.PDF"
}
],
"people": [
{
"name": "Alatalo Bros",
"role": "Applicant",
"contact": "02 6055 0180"
}
],
"extended": {
"software_vendor": "Civica",
"software_vendor_url": "http://www.civica.com.au"
}
}
}
],
"count": 4,
"pagination": {
"previous": null,
"next": 2,
"current": 1,
"per_page": 4,
"count": 24091,
"pages": 6023
}
}'
select *
from OPENJSON(#json, '$.response')
with
([lot] varchar(200) '$.application.locations[0].land_title_ref.torrens.lot',
[section] varchar(200) '$.application.locations[0].land_title_ref.torrens.section',
[dpsp_id] varchar(200) '$.application.locations[0].land_title_ref.torrens.dpsp_id',
[Street] varchar(200) '$.application.locations[0].address.street',
[suburb] varchar(200) '$.application.locations[0].address.suburb',
[state] varchar(200) '$.application.locations[0].address.state',
[postcode] varchar(200) '$.application.locations[0].address.postcode',
[geometry] varchar(200) '$.application.locations[0].geometry'
)
Try this:
select L.*
from OPENJSON(#json,'$.response') R
CROSS APPLY OPENJSON(R.[value], '$.application.locations')
with
(
[lot] varchar(200) '$.land_title_ref.torrens.lot',
[section] varchar(200) '$.land_title_ref.torrens.section',
[dpsp_id] varchar(200) '$.land_title_ref.torrens.dpsp_id',
[Street] varchar(200) '$.address.street',
[suburb] varchar(200) '$.address.suburb',
[state] varchar(200) '$.address.state',
[postcode] varchar(200) '$.address.postcode',
[geometry] varchar(200) '$.geometry'
) L
The locations is an array, so we need to use cross apply and OPENSJON to get all elements.

How do I loop the JSON Request with different customer object data in Postman?

How do I loop the JSON Request with different customer object data in POSTMAN?
I'm looking to load a web application with test data.
{
"customer": {
"external_id": "EXT1221",
"name": "Elon Musk",
"address": "1405 North Ave, Chicago",
"address_second_line": "Apt 2",
"phone": "522-525-5555",
"email": "elon#company.com",
"zipcode": "60612",
"lat": "40.7833404",
"lng" : "-73.9527781",
"merchant_id" : 11271,
"confirmation_code" : "5320",
"allow_login" : true,
"allow_sending_email" : true,
"allow_sending_sms" : true,
"language": "en"
}
}
Since you have not defined structure how you would like to keep data. It looks like you are assuming data will be like :
{
"customers": {
"external_id": "EXT1221",
"name": "Elon Musk",
"address": "1405 North Ave, Chicago",
"address_second_line": "Apt 2",
"phone": "522-525-5555",
"email": "elon#company.com",
"zipcode": "60612",
"lat": "40.7833404",
"lng": "-73.9527781",
"merchant_id": 11271,
"confirmation_code": "5320",
"allow_login": true,
"allow_sending_email": true,
"allow_sending_sms": true,
"language": "en"
},
"customer": {
"external_id": "EXT1222",
"name": "Elon Musk2",
"address": "1405 North Ave, Chicago",
"address_second_line": "Apt 2",
"phone": "522-525-5555",
"email": "elon2#company.com",
"zipcode": "60612",
"lat": "40.7833404",
"lng": "-73.9527781",
"merchant_id": 11271,
"confirmation_code": "5320",
"allow_login": true,
"allow_sending_email": true,
"allow_sending_sms": true,
"language": "en"
}
}
In this case you can iterate as below :
Assuming testData is storing this JSON data.
_.each(testData,function(value,key){
console.log(`${JSON.stringify(key)} ${JSON.stringify(value)}`);
})
There is another way to do if JSON looks like as below :
{
"customers": [
{
"external_id": "EXT1221",
"name": "Elon Musk",
"address": "1405 North Ave, Chicago",
"address_second_line": "Apt 2",
"phone": "522-525-5555",
"email": "elon#company.com",
"zipcode": "60612",
"lat": "40.7833404",
"lng": "-73.9527781",
"merchant_id": 11271,
"confirmation_code": "5320",
"allow_login": true,
"allow_sending_email": true,
"allow_sending_sms": true,
"language": "en"
},
{
"external_id": "EXT1222",
"name": "Elon Musk2",
"address": "1405 North Ave, Chicago",
"address_second_line": "Apt 2",
"phone": "522-525-5555",
"email": "elon2#company.com",
"zipcode": "60612",
"lat": "40.7833404",
"lng": "-73.9527781",
"merchant_id": 11271,
"confirmation_code": "5320",
"allow_login": true,
"allow_sending_email": true,
"allow_sending_sms": true,
"language": "en"
}
]
}
Then you can iterate for each customer as below:
assuming testData storing above JSON.
_.each(testData.customers,function(customer){
console.log(customer);
});

Resources