Re: Stripping a JSON of extra characters in PHP
Ben Bacarisse <[email protected]> Wed, 01 Feb 2023 16:09:00 +0000
| Newsgroups | comp.lang.php |
|---|---|
| Organization | A noiseless patient Spider |
| Message-ID | <[email protected]> |
[email protected] (The Doctor) writes: > From https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet > > I need a JSON as follows: > > { > "store_id":"moneris", > "api_token":"hurgle", What you pasted as what you "need" is not even valid JSON and has a huge number of pointless spaces in it making it almost unreadable (in my news client). > But in testng I am getting > > [{"store_id":"store3","api_token":"yesguy","checkout_id":"chkt23NGFtore3","txn_total":"126.00","environment":"qa","action":"preload"},[{"cart":[[[{"items":{"url":"https:\/\/www.pdsolutions.ca\/images\/newwhiteheader.png","description":"Agricultural Health Study","product_code":"AHS-1298","unit_cost":60,"quantity":"1"},"subtotal":60,"tax":{"amount":3,"description":"GST","rate":"0.05"}},{"items":{"url":"https:\/\/www.pdsolutions.ca\/images\/newwhiteheader.png","description":"Pesticide Applicator Records","product_code":"PAR-1302","unit_cost":60,"quantity":"1"},"subtotal":60,"tax":{"amount":3,"description":"GST","rate":"0.05"}}]]]}],[{"contact_details":{"first_name":"Dave","last_name":"Yadallee","email":"[email protected]","phone":"7809999999"}}],[{"billing_details":{"address_1":"","city":"","province":"","country":"CA","postal_code":""}}]] > > How can I carefully strip unnecessary punctuation? But that one is (a) valid and (b) has no unnecessary punctuation, so I don't know what it is you mean. -- Ben.