dbeck121 / CPI-Helper-Chrome-Extension

52 stars 18 forks source link

JSON body beautify issue #148

Open veraciousnottaken opened 4 months ago

veraciousnottaken commented 4 months ago

Hi

I have this valid JSON body: { "CBO_xxx": { "CBO_xxx": { "ObjectID": "94854098609347567568678679694059", "Cl": "143", "Cl": "Erfasst", "Re": "ok", "Re": "", "Re": "", "Note": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Daisy_Response>\n <result>\n <status>ok</status>\n <error/>\n <error_description/>\n </result>\n <claim>\n <jobno>616825</jobno>\n <trno>404349</trno>\n <lsno/>\n <created>08042024 074644</created>\n <manufacturer>AMICA</manufacturer>\n <model>1191465</model>\n <group>38</group>\n <servicetype>Standard</servicetype>\n <serialno>11914653247293</serialno>\n <identno>EGSPV 5E97 205</identno>\n <rma/>\n <status>143</status>\n <status_text>Erfasst</status_text>\n <mandator>1</mandator>\n <mandatorname> direkte Abrechnung</mandatorname>\n <warranty>1</warranty>\n <kph>F</kph>\n <stock>F</stock>\n <purchase_date>04042024</purchase_date>\n <error>pumpt nicht ab\n</error>\n <vip>F</vip>\n <visit_date/>\n <client>\n <first_name>Marius</first_name>\n <last_name>Thorsen</last_name>\n <street>Kongens gate 123</street>\n <zip>0155</zip>\n <city>Oslo</city>\n <phone1>+4712345678</phone1>\n <phone2/>\n <telefax/>\n <mobile>+4798765432</mobile>\n <email>marius.thorsen@example.com</email>\n </client>\n <dealer>\n <title/>\n <first_name/>\n <last_name/>\n <street/>\n <zip/>\n <city/>\n <phone1/>\n <phone2/>\n <telefax/>\n <mobile/>\n <email/>\n </dealer>\n <customer>\n <title/>\n <first_name/>\n <last_name/>\n <street/>\n <zip/>\n <city/>\n <phone1/>\n <phone2/>\n <telefax/>\n <mobile/>\n <email/>\n </customer>\n <historylist>\n <history>\n <origin>XMLSERVER</origin>\n <date>08042024 074644</date>\n <status>427</status>\n <status_text>Auftrag von Amica abgeholt</status_text>\n <info/>\n </history>\n <history>\n <origin>DSCHAEFER</origin>\n <date>08042024 094607</date>\n <status>1</status>\n <status_text>Erfasst</status_text>\n <info/>\n </history>\n <history>\n <origin>DSCHAEFER</origin>\n <date>08042024 100347</date>\n <status>143</status>\n <status_text>Erfasst</status_text>\n <info/>\n </history>\n </historylist>\n </claim>\n</Daisy_Response>\n", "EntityLastReadedOn": "2024-04-08T11:50:29.548Z", "Cl": "616825", "Cl": "404349", "Z_": "2024-04-08T08:03:47.000Z" } } }

and it's rendered as image

basically after some sequence in "Note" text if cut, it should be: image

(Data in body are anonymized).

dbeck121 commented 4 months ago

Hi,

thanks for the issue. Yes that could be displayed way better. Unfortunately I do not see a chance to do that with prettify library that we use. Maybe we will switch engine the next years but for now the time is better invested in other features/bugs.

incpi commented 4 months ago

Hello, addition is because of below logic,

const jsonString = '{"message": "This is a \\"quoted\\" message" }';
console.log(jsonString); // Output: {"message": "This is a \"quoted\" message"}

see here, how \" in a JSON string (or JavaScript string) represents an escaped double quote ("), So, even your JSON is valid but as String it's not valid.

Please feel free if you want to implement & add and then raise PR. We much appreciated your contribution.