shamblett / xml2json

XML to JSON conversion for Dart
MIT License
54 stars 19 forks source link

Lost Data when converting from XML to json #61

Closed Jacksonericd closed 8 months ago

Jacksonericd commented 1 year ago

This is the XML i am trying to parse into json :

xml_input

And the expected output is :

{ "Result": { "ErrorNo": 0, "Message": "Success", "Rows": { "R": [ { "C": [ { "FA": 1, "SA": 0, "RE": 1 }, 19072023011, "Hiragappa shivappa Naduvinaker", 600, "SUGAR PACKING 1KG POUCH,SUGAR PACK", "RTGS", 3000, "-", 10010000122, "KVGB0003211", "23/08/2023", "KARIBASAPPA B C", "10,000.00 Dr", 89113391461, "CA", "", "Pending", "" ] }, { "C": [ { "FA": 1, "SA": 0, "RE": 1 }, 19072023012, "MSM Services", 650, "CATRIDGE REFILL AND DRUM 2NOS", "Internal", 3000, "-", 10010000123, "ICIC0002815", "23/08/2023", "SHIVALEELA B S", "30,000.00 Dr", 12458689521, "CA", "", "Pending", "" ] } ] } } }

But it returned :

{ "Result": { "ErrorNo": "0", "Message": "Success", "Rows": { "R": [ { "C": [ "19072023011", "Hiragappa shivappa Naduvinaker", "600", "SUGAR PACKING 1KG POUCH,SUGAR PACK", "RTGS", "3000", "-", "00010010000122", "KVGB0003211", "23/08/2023", "KARIBASAPPA B C", "10,000.00 Dr", "89113391461", "CA", "", "Pending", "" ] }, { "C": [ "19072023012", "MSM Services", "650", "CATRIDGE REFILL AND DRUM 2NOS", "Internal", "3000", "-", "00010010000123", "ICIC0002815", "23/08/2023", "SHIVALEELA B S", "30,000.00 Dr", "12458689521", "CA", "", "Pending", "" ] } ] } } }

I lost the first value inside the List 'C' . (Eg: { "FA": 1, "SA": 0, "RE": 1 }, )

shamblett commented 1 year ago

OK thanks, I'll have a look at this.

shamblett commented 1 year ago

Could you supply the input XML as text rather than an image, thanks.

Jacksonericd commented 1 year ago

Could you supply the input XML as text rather than an image, thanks.

Please find the input XML :

0 Success 1 0 1 19072023011 Hiragappa shivappa Naduvinaker 600 SUGAR PACKING 1KG POUCH,SUGAR PACK RTGS 3000 - 00010010000122 KVGB0003211 23/08/2023 KARIBASAPPA B C 10,000.00 Dr 89113391461 CA Pending 1 0 1 19072023012 MSM Services 650 CATRIDGE REFILL AND DRUM 2NOS Internal 3000 - 00010010000123 ICIC0002815 23/08/2023 SHIVALEELA B S 30,000.00 Dr 12458689521 CA Pending

FTA XML.txt

shamblett commented 1 year ago

This is because the implementation of the Parker transform in this package has always done this, if you look at the test strings -

String complexXmlTestString = 
...
'<report_id>637619</report_id>'
....

and the corresponding expected json -

String parkerComplexJsonCheckString = '{'
...
 '"report_id":"637619",'
...

you can see that the integer value of report id is quoted which is what you are seeing.

The original Parker transform algorithm I based this on back in 2013 is unfortunately lost in time however it has been like this since then. I don't want to change this as it will break expected behaviour for many users.

A better approach would be to add another Parker transform like the toParkerWithAttributes transform named toParkerModern or something similar but this would take more time.