U.xmlToJson() produces emtpy objects when tag is emtpy
See original GitHub issueI am trying to convert this XML to JSON :
<result>
<SalHdr>
<SalId>32745</SalId>
<BillNo>32745</BillNo>
<BillDt>2020-09-05T00:00:00</BillDt>
<BookId>1</BookId>
<Cash>CA</Cash>
<BillRefNo>0032745</BillRefNo>
<PtyId>0</PtyId>
<PtyName></PtyName> // look here
<Add1></Add1> // look here
<City></City> // look here
<TotAmt>247.61</TotAmt>
<TaxId>4</TaxId>
<Taxper>0.00</Taxper>
<TaxAmt>12.38</TaxAmt>
<RndOff>0.01</RndOff>
<NetAmt>260.00</NetAmt>
<DiscAmt>0.00</DiscAmt>
<Discper>0.00</Discper>
<Remarks></Remarks>
<UserId>2</UserId>
<CompId>1</CompId>
<AcYrId>12</AcYrId>
<DocCancel>0</DocCancel>
<OtherState>0</OtherState>
<WaiterId>4</WaiterId>
<WaiterCode>4</WaiterCode>
<DeliveryId>0</DeliveryId>
<Delivery>CASH</Delivery>
<Est>0</Est>
<BillTime>2020-09-05T09:08:49</BillTime>
</SalHdr>
<SalHdr>
<SalId>32746</SalId>
<BillNo>32746</BillNo>
<BillDt>2020-09-05T00:00:00</BillDt>
<BookId>1</BookId>
<Cash>CA</Cash>
<BillRefNo>0032746</BillRefNo>
<PtyId>0</PtyId>
<PtyName></PtyName>
<Add1></Add1>
<City></City>
<TotAmt>404.74</TotAmt>
<TaxId>4</TaxId>
<Taxper>0.00</Taxper>
<TaxAmt>20.24</TaxAmt>
<RndOff>0.02</RndOff>
<NetAmt>425.00</NetAmt>
<DiscAmt>0.00</DiscAmt>
<Discper>0.00</Discper>
<Remarks></Remarks>
<UserId>2</UserId>
<CompId>1</CompId>
<AcYrId>12</AcYrId>
<DocCancel>0</DocCancel>
<OtherState>0</OtherState>
<WaiterId>1</WaiterId>
<WaiterCode>1</WaiterCode>
<DeliveryId>0</DeliveryId>
<Delivery>CASH</Delivery>
<Est>0</Est>
<BillTime>2020-09-05T09:11:21</BillTime>
</SalHdr>
Here the PtyName, add1,city is empty . In json I am getting as empty {} instead of emtpy string or null
{
"results" : {
[
{
"SalId": "32745",
"BillNo": "32745",
"BillDt": "2020-09-05T00:00:00",
"BookId": "1",
"Cash": "CA",
"BillRefNo": "0032745",
"PtyId": "0",
"PtyName": {}, // look here
"Add1": {}, // look here
"City": {}, // look here
"TotAmt": "247.61",
"TaxId": "4",
"Taxper": "0.00",
"TaxAmt": "12.38",
"RndOff": "0.01",
"NetAmt": "260.00",
"DiscAmt": "0.00",
"Discper": "0.00",
"Remarks": {},
"UserId": "2",
"CompId": "1",
"AcYrId": "12",
"DocCancel": "0",
"OtherState": "0",
"WaiterId": "4",
"WaiterCode": "4",
"DeliveryId": "0",
"Delivery": "CASH",
"Est": "0",
"BillTime": "2020-09-05T09:08:49",
"ID": "1"
},
{
"SalId": "32746",
"BillNo": "32746",
"BillDt": "2020-09-05T00:00:00",
"BookId": "1",
"Cash": "CA",
"BillRefNo": "0032746",
"PtyId": "0",
"PtyName": {},
"Add1": {},
"City": {},
"TotAmt": "404.74",
"TaxId": "4",
"Taxper": "0.00",
"TaxAmt": "20.24",
"RndOff": "0.02",
"NetAmt": "425.00",
"DiscAmt": "0.00",
"Discper": "0.00",
"Remarks": {},
"UserId": "2",
"CompId": "1",
"AcYrId": "12",
"DocCancel": "0",
"OtherState": "0",
"WaiterId": "1",
"WaiterCode": "1",
"DeliveryId": "0",
"Delivery": "CASH",
"Est": "0",
"BillTime": "2020-09-05T09:11:21",
"ID": "2"
}
]
]
}
Please help me in this issue since it breaking the model classes
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
php - json_encode creates empty objects for empty XML tags
You can try $xml = '<Family> <name>aaa</name> ... I think the function filterEmptyArray() above needs an addition to it to dont delete zeros...
Read more >JSON API version: 20180813 converts empty xml elements to ...
For empty xml element, version:20090211 returns empty JSON Object ({}) ... XML generates empty strings instead of empty objects:.
Read more >Handling JSON null and empty arrays and objects - IBM
JSON data has the concept of null and empty arrays and objects. This section explains how each of these concepts is mapped to...
Read more >Mapping Between JSON and XML - WCF | Microsoft Learn
If there are no CIIs, it maps to an empty JSON string . Example: The following element maps to a JSON fragment: <root...
Read more >JSON Content Patterns - Oracle Help Center
Set the Enforce Empty JSON Object Payload target element to true in the mapper. Use the JavaScript function true(). You can enter this...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @RageshAntony,
Thank you for the issue. I can add a new mode REPLACE_EMPTY_VALUE_WITH_NULL to the U.xmlToJson() method.
Is it a suitable solution?
oh thanks . Thanks for developing this feature and thanks once again for remembering me and notifying