Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Linux - Das System fuer schlaue Maedchen ;) -- banshee


devel / comp.lang.php / Stripping a JSON of extra characters in PHP

SubjectAuthor
* Stripping a JSON of extra characters in PHPThe Doctor
+* Re: Stripping a JSON of extra characters in PHPBen Bacarisse
|+* Re: Stripping a JSON of extra characters in PHPArno Welzel
||`* Re: Stripping a JSON of extra characters in PHPBen Bacarisse
|| `* Re: Stripping a JSON of extra characters in PHPArno Welzel
||  `* Re: Stripping a JSON of extra characters in PHPBen Bacarisse
||   `* Re: Stripping a JSON of extra characters in PHPArno Welzel
||    `* Re: Stripping a JSON of extra characters in PHPBen Bacarisse
||     `- Re: Stripping a JSON of extra characters in PHPArno Welzel
|`* Re: Stripping a JSON of extra characters in PHPJ.O. Aho
| +- Re: Stripping a JSON of extra characters in PHPArno Welzel
| `- Re: Stripping a JSON of extra characters in PHPBen Bacarisse
`* Re: Stripping a JSON of extra characters in PHPJ.O. Aho
 `* Re: Stripping a JSON of extra characters in PHPThe Doctor
  `* Re: Stripping a JSON of extra characters in PHPJ.O. Aho
   `* Re: Stripping a JSON of extra characters in PHPThe Doctor
    +* Re: Stripping a JSON of extra characters in PHPJ.O. Aho
    |`- Re: Stripping a JSON of extra characters in PHPThe Doctor
    `* Re: Stripping a JSON of extra characters in PHPArno Welzel
     `* Re: Stripping a JSON of extra characters in PHPThe Doctor
      +* Re: Stripping a JSON of extra characters in PHPThe Doctor
      |`* Re: Stripping a JSON of extra characters in PHPArno Welzel
      | +* Re: Stripping a JSON of extra characters in PHPArno Welzel
      | |`* Re: Stripping a JSON of extra characters in PHPThe Doctor
      | | `* Re: Stripping a JSON of extra characters in PHPArno Welzel
      | |  `- Re: Stripping a JSON of extra characters in PHPThe Doctor
      | `- Re: Stripping a JSON of extra characters in PHPThe Doctor
      `* Re: Stripping a JSON of extra characters in PHPArno Welzel
       `- Re: Stripping a JSON of extra characters in PHPThe Doctor

Pages:12
Stripping a JSON of extra characters in PHP

<tre1ei$2lti$75@gallifrey.nk.ca>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=783&group=comp.lang.php#783

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.nk.ca!.POSTED.doctor.nl2k.ab.ca!not-for-mail
From: doctor@doctor.nl2k.ab.ca (The Doctor)
Newsgroups: comp.lang.php
Subject: Stripping a JSON of extra characters in PHP
Date: Wed, 1 Feb 2023 15:45:22 -0000 (UTC)
Organization: NetKnow News
Message-ID: <tre1ei$2lti$75@gallifrey.nk.ca>
Injection-Date: Wed, 1 Feb 2023 15:45:22 -0000 (UTC)
Injection-Info: gallifrey.nk.ca; posting-host="doctor.nl2k.ab.ca:204.209.81.1";
logging-data="87986"; mail-complaints-to="usenet@gallifrey.nk.ca"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: doctor@doctor.nl2k.ab.ca (The Doctor)
 by: The Doctor - Wed, 1 Feb 2023 15:45 UTC

From https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet

I need a JSON as follows:

{
"store_id":"moneris",
"api_token":"hurgle",
"checkout_id":"chkt5BF66neris",
"txn_total":"452.00",
"environment":"qa",
"action":"preload",
"token": [
{
"data_key": "abc123datakey1",
"issuer_id": "645sddfvdrt4tefd"
},
{
"data_key": "abc123datakey2",
"issuer_id": "645sddfvdrt4tefd"
},
{
"data_key": "abc123datakey3",
"issuer_id": "645sddfvdrt4tefd"
}
],
"ask_cvv":"Y"
"order_no":"",
"cust_id":"chkt - cust - 0303",
"dynamic_descriptor":"dyndesc",
"language":"en",
"recur":{
"bill_now":"true",
"recur_amount":"1.00",
"start_date":"2021-11-21",
"recur_unit":"month",
"recur_period":"1",
"number_of_recurs":"10"
},
"cart":{
"items":[
{
"url":"https:\/\/example.com\/examples\/item1.jpg",
"description":"One item",
"product_code":"one_item",
"unit_cost":"100.00",
"quantity":"1"
},
{
"url":"https:\/\/example.com\/examples\/item2.jpg",
"description":"Two item",
"product_code":"two_item",
"unit_cost":"200.00",
"quantity":"1"
},
{
"url":"https:\/\/example.com\/examples\/item3.jpg",
"description":"Three item",
"product_code":"three_item",
"unit_cost":"100.00",
"quantity":"1"
}
],
"subtotal":"400.00",
"tax":{
"amount":"52.00",
"description":"Taxes",
"rate":"13.00"
}
},
"contact_details":{
"first_name":"bill",
"last_name":"smith",
"email":"test@moneris.com",
"phone":"4165551234"
},
"shipping_details":{
"address_1":"1 main st",
"address_2":"Unit 2012",
"city":"Toronto",
"province":"ON",
"country":"CA",
"postal_code":"M1M1M1"
},
"billing_details":{
"address_1":"1 main st",
"address_2":"Unit 2000",
"city":"Toronto",
"province":"ON",
"country":"CA",
"postal_code":"M1M1M1"
}
}

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":"dog@nk.ca","phone":"7809999999"}}],[{"billing_details":{"address_1":"","city":"","province":"","country":"CA","postal_code":""}}]]


How can I carefully strip unnecessary punctuation?
--
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b
When they offer free stuff, demand to know how much it will cost. -unknown Beware https://mindspring.com

Re: Stripping a JSON of extra characters in PHP

<875yclmkpv.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=784&group=comp.lang.php#784

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Wed, 01 Feb 2023 16:09:00 +0000
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <875yclmkpv.fsf@bsb.me.uk>
References: <tre1ei$2lti$75@gallifrey.nk.ca>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="8af5a25f65a180076c231dd255ed6002";
logging-data="440026"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+jsQOxDDiPYqKQ9IX4JtZHEp0bR4szCwM="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:q6MVUfIMgbLF7/DcFCmLNfAofXI=
sha1:cMXHObn0bUPmioSjx06qmpFqJ4o=
X-BSB-Auth: 1.61118943b7e56e4ce1ea.20230201160900GMT.875yclmkpv.fsf@bsb.me.uk
 by: Ben Bacarisse - Wed, 1 Feb 2023 16:09 UTC

doctor@doctor.nl2k.ab.ca (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":"dog@nk.ca","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.

Re: Stripping a JSON of extra characters in PHP

<k44tjfFku3dU3@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=785&group=comp.lang.php#785

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@arnowelzel.de (Arno Welzel)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Fri, 3 Feb 2023 18:12:15 +0100
Lines: 205
Message-ID: <k44tjfFku3dU3@mid.individual.net>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <875yclmkpv.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: individual.net RVcfuSbO6c6qqacpFqweewbWJrgYad79yMqAoYuOcJDn+fzlRz
Cancel-Lock: sha1:PW7Q/uqK0qVHwPky7ATvas1b1TM=
Content-Language: de-DE
In-Reply-To: <875yclmkpv.fsf@bsb.me.uk>
 by: Arno Welzel - Fri, 3 Feb 2023 17:12 UTC

Ben Bacarisse, 2023-02-01 17:09:

> doctor@doctor.nl2k.ab.ca (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).

First of all - to all of you: learn how to use validators and
beautifiers. It helps a lot to understand the structure and differences
between multiple JSON files.

In the original sample was only one single comma missing. Otherwise it
is ok:

{
"store_id":"moneris",
"api_token":"hurgle",
"checkout_id":"chkt5BF66neris",
"txn_total":"452.00",
"environment":"qa",
"action":"preload",
"token":[
{
"data_key":"abc123datakey1",
"issuer_id":"645sddfvdrt4tefd"
},
{
"data_key":"abc123datakey2",
"issuer_id":"645sddfvdrt4tefd"
},
{
"data_key":"abc123datakey3",
"issuer_id":"645sddfvdrt4tefd"
}
],
"ask_cvv":"Y",
"order_no":"",
"cust_id":"chkt - cust - 0303",
"dynamic_descriptor":"dyndesc",
"language":"en",
"recur":{
"bill_now":"true",
"recur_amount":"1.00",
"start_date":"2021-11-21",
"recur_unit":"month",
"recur_period":"1",
"number_of_recurs":"10"
},
"cart":{
"items":[
{
"url":"https:\/\/example.com\/examples\/item1.jpg",
"description":"One item",
"product_code":"one_item",
"unit_cost":"100.00",
"quantity":"1"
},
{
"url":"https:\/\/example.com\/examples\/item2.jpg",
"description":"Two item",
"product_code":"two_item",
"unit_cost":"200.00",
"quantity":"1"
},
{
"url":"https:\/\/example.com\/examples\/item3.jpg",
"description":"Three item",
"product_code":"three_item",
"unit_cost":"100.00",
"quantity":"1"
}
],
"subtotal":"400.00",
"tax":{
"amount":"52.00",
"description":"Taxes",
"rate":"13.00"
}
},
"contact_details":{
"first_name":"bill",
"last_name":"smith",
"email":"test@moneris.com",
"phone":"4165551234"
},
"shipping_details":{
"address_1":"1 main st",
"address_2":"Unit 2012",
"city":"Toronto",
"province":"ON",
"country":"CA",
"postal_code":"M1M1M1"
},
"billing_details":{
"address_1":"1 main st",
"address_2":"Unit 2000",
"city":"Toronto",
"province":"ON",
"country":"CA",
"postal_code":"M1M1M1"
}
}

>> 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":"dog@nk.ca","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.

The structure is completely different and not just with "unnecessary
punctuation" - there is no simple way to "strip" anything, it has to be
completely parsed and output again in the desired way:

[
{
"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":"dog@nk.ca",
"phone":"7809999999"
}
}
],
[
{
"billing_details":{
"address_1":"",
"city":"",
"province":"",
"country":"CA",
"postal_code":""
}
}
]
]

--
Arno Welzel
https://arnowelzel.de

Re: Stripping a JSON of extra characters in PHP

<87ilgis3p2.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=786&group=comp.lang.php#786

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Fri, 03 Feb 2023 23:56:57 +0000
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <87ilgis3p2.fsf@bsb.me.uk>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <875yclmkpv.fsf@bsb.me.uk>
<k44tjfFku3dU3@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="b078c8aa186988c93347ba82ce7f4a38";
logging-data="1743372"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18t+uqKJ9lgFSDKc0PmEgvv8JVu15wcAlk="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:TgRfk2PagcVJZ+kQz9u1cUhvVaM=
sha1:nHfqdztJkHlhzBgAIjJXu5kcsM0=
X-BSB-Auth: 1.a737935864f59d8f47d5.20230203235657GMT.87ilgis3p2.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 3 Feb 2023 23:56 UTC

Arno Welzel <usenet@arnowelzel.de> writes:

> Ben Bacarisse, 2023-02-01 17:09:
>
>> doctor@doctor.nl2k.ab.ca (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).
>
> First of all - to all of you: learn how to use validators and
> beautifiers.

You think I don't? Now that you've got that off your chest, what's the
second thing we -- all of us -- need to learn? ;-)

--
Ben.

Re: Stripping a JSON of extra characters in PHP

<k46q0rF1ne9U4@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=787&group=comp.lang.php#787

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!lilly.ping.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: user@example.net (J.O. Aho)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Sat, 4 Feb 2023 11:23:23 +0100
Lines: 21
Message-ID: <k46q0rF1ne9U4@mid.individual.net>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <875yclmkpv.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net Jhge1pXwVhFc7/EI+XkVmw8JFAI1KuOJdKoegBPh59W0kwt62D
Cancel-Lock: sha1:/UUl17/DYJDqARLfEF6LxPAErrs=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Content-Language: en-US-large
In-Reply-To: <875yclmkpv.fsf@bsb.me.uk>
 by: J.O. Aho - Sat, 4 Feb 2023 10:23 UTC

On 01/02/2023 17:09, Ben Bacarisse wrote:
> doctor@doctor.nl2k.ab.ca (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).
> I don't know what it is you mean.
As I saw it, the OP post was more about the formatting of the json that
is generated than about if his json was correct or not, he wants a multi
line json with indentations instead of a single line compressed json.

--
//Aho

Re: Stripping a JSON of extra characters in PHP

<k4881fF6dctU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=789&group=comp.lang.php#789

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!lilly.ping.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@arnowelzel.de (Arno Welzel)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Sun, 5 Feb 2023 00:28:48 +0100
Lines: 34
Message-ID: <k4881fF6dctU1@mid.individual.net>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <875yclmkpv.fsf@bsb.me.uk>
<k44tjfFku3dU3@mid.individual.net> <87ilgis3p2.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: individual.net uveGqnrMtlyjS9rF7TEb9gQaBOTfP1C1f9LgRlkFRLLBWEg1Qt
Cancel-Lock: sha1:dzJinBXXEXsE5vQa+xbzVpR6dc4=
Content-Language: de-DE
In-Reply-To: <87ilgis3p2.fsf@bsb.me.uk>
 by: Arno Welzel - Sat, 4 Feb 2023 23:28 UTC

Ben Bacarisse, 2023-02-04 00:56:

> Arno Welzel <usenet@arnowelzel.de> writes:
>
>> Ben Bacarisse, 2023-02-01 17:09:
>>
>>> doctor@doctor.nl2k.ab.ca (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).
>>
>> First of all - to all of you: learn how to use validators and
>> beautifiers.
>
> You think I don't? Now that you've got that off your chest, what's the
> second thing we -- all of us -- need to learn? ;-)

What I told you. Then you could have seen, that the invalid example only
missed a comma.

--
Arno Welzel
https://arnowelzel.de

Re: Stripping a JSON of extra characters in PHP

<k48847F6dctU2@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=790&group=comp.lang.php#790

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@arnowelzel.de (Arno Welzel)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Sun, 5 Feb 2023 00:30:16 +0100
Lines: 29
Message-ID: <k48847F6dctU2@mid.individual.net>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <875yclmkpv.fsf@bsb.me.uk>
<k46q0rF1ne9U4@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: individual.net yRZf2stGw7FpXyw+Qkk43Ae7P724pUNkqb9zr4kd/nbK+OuVkx
Cancel-Lock: sha1:4a00pTJtavQSBStgYLpmh4yLp7U=
Content-Language: de-DE
In-Reply-To: <k46q0rF1ne9U4@mid.individual.net>
 by: Arno Welzel - Sat, 4 Feb 2023 23:30 UTC

J.O. Aho, 2023-02-04 11:23:

> On 01/02/2023 17:09, Ben Bacarisse wrote:
>> doctor@doctor.nl2k.ab.ca (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).
>> I don't know what it is you mean.
> As I saw it, the OP post was more about the formatting of the json that
> is generated than about if his json was correct or not, he wants a multi
> line json with indentations instead of a single line compressed json.

The OP showed to examples of *similar* JSON data with many identical
properties, but in a slightly different structure. So I am not sure if
the question was onloy about formatting - but only the OP can tell.

--
Arno Welzel
https://arnowelzel.de

Re: Stripping a JSON of extra characters in PHP

<87k00xq9l8.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=791&group=comp.lang.php#791

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Sat, 04 Feb 2023 23:44:51 +0000
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <87k00xq9l8.fsf@bsb.me.uk>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <875yclmkpv.fsf@bsb.me.uk>
<k46q0rF1ne9U4@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="5975cb4157a41d16b46a615111281563";
logging-data="2297916"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19jOpjjmj0l2+AMHdYAgS9UFMDKqQuJ80E="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:OHbys7FonbJx/y6D5U8ajXjeSjg=
sha1:n+jLjPjA9C9V49HTb5PqPb0M3dw=
X-BSB-Auth: 1.5780cc985315e63e3a2d.20230204234451GMT.87k00xq9l8.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 4 Feb 2023 23:44 UTC

"J.O. Aho" <user@example.net> writes:

> On 01/02/2023 17:09, Ben Bacarisse wrote:
>> doctor@doctor.nl2k.ab.ca (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). I don't know what it is you mean.
>
> As I saw it, the OP post was more about the formatting of the json
> that is generated than about if his json was correct or not, he wants
> a multi line json with indentations instead of a single line
> compressed json.

Weird. I didn't interpret a desire to "strip unnecessary punctuation"
as a formatting question, but I suppose it could be: unnecessary for
display even though necessary for valid syntax.

--
Ben.

Re: Stripping a JSON of extra characters in PHP

<87edr5q8lu.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=792&group=comp.lang.php#792

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Sun, 05 Feb 2023 00:06:05 +0000
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <87edr5q8lu.fsf@bsb.me.uk>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <875yclmkpv.fsf@bsb.me.uk>
<k44tjfFku3dU3@mid.individual.net> <87ilgis3p2.fsf@bsb.me.uk>
<k4881fF6dctU1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="5975cb4157a41d16b46a615111281563";
logging-data="2308480"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+j0lOa/RRQpifG5Tl5ngna3Exy1A+GmjE="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:JfcZSS3ay/FyjuhGpkgKv1zDTy4=
sha1:pHGoeRwwRLx6iVAiVCo5FXHQUno=
X-BSB-Auth: 1.d878025e843a7b02d24b.20230205000605GMT.87edr5q8lu.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 5 Feb 2023 00:06 UTC

Arno Welzel <usenet@arnowelzel.de> writes:

> Ben Bacarisse, 2023-02-04 00:56:
>
>> Arno Welzel <usenet@arnowelzel.de> writes:
>>
>>> Ben Bacarisse, 2023-02-01 17:09:
>>>
>>>> doctor@doctor.nl2k.ab.ca (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).
>>>
>>> First of all - to all of you: learn how to use validators and
>>> beautifiers.
>>
>> You think I don't? Now that you've got that off your chest, what's the
>> second thing we -- all of us -- need to learn? ;-)
>
> What I told you.

What a relief to know that you'd already imparted the first /and second
thing/ we all need to learn. I feared I would not have the time to
learn enough to keep posting!

> Then you could have seen, that the invalid example only
> missed a comma.

Yes, I spotted that too. You'll never guess how...

--
Ben.

Re: Stripping a JSON of extra characters in PHP

<k49ojdFdcn7U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=793&group=comp.lang.php#793

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@arnowelzel.de (Arno Welzel)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Sun, 5 Feb 2023 14:17:33 +0100
Lines: 19
Message-ID: <k49ojdFdcn7U1@mid.individual.net>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <875yclmkpv.fsf@bsb.me.uk>
<k44tjfFku3dU3@mid.individual.net> <87ilgis3p2.fsf@bsb.me.uk>
<k4881fF6dctU1@mid.individual.net> <87edr5q8lu.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: individual.net 7YasjF10Wmc/r6wBclvJUg6orMp94xzcnc8KfLPqceb6TdLhmI
Cancel-Lock: sha1:S5mxQthvFtHYeLnFVIHShUdztc0=
Content-Language: de-DE
In-Reply-To: <87edr5q8lu.fsf@bsb.me.uk>
 by: Arno Welzel - Sun, 5 Feb 2023 13:17 UTC

Ben Bacarisse, 2023-02-05 01:06:

> Arno Welzel <usenet@arnowelzel.de> writes:
[...]
>> Then you could have seen, that the invalid example only
>> missed a comma.
>
> Yes, I spotted that too. You'll never guess how...

Well, then I wonder why you just wrote this:

"But that one is (a) valid and (b) has no unnecessary punctuation, so I
don't know what it is you mean."

--
Arno Welzel
https://arnowelzel.de

Re: Stripping a JSON of extra characters in PHP

<k49veoF1ne8U3@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=794&group=comp.lang.php#794

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: user@example.net (J.O. Aho)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Sun, 5 Feb 2023 16:14:32 +0100
Lines: 56
Message-ID: <k49veoF1ne8U3@mid.individual.net>
References: <tre1ei$2lti$75@gallifrey.nk.ca>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net ap7VwiW8ih2J/Lin7TnMYQFbiK1rbtoxVVAduizuhw3dMDLnhq
Cancel-Lock: sha1:A+RVwjPFA6pWNWLyHfgFfrIz6hU=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Content-Language: en-US-large
In-Reply-To: <tre1ei$2lti$75@gallifrey.nk.ca>
 by: J.O. Aho - Sun, 5 Feb 2023 15:14 UTC

On 01/02/2023 16:45, The Doctor wrote:
> From https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
>
> I need a JSON as follows:
>
> {
> "store_id":"moneris",
> "api_token":"hurgle",

For console output:
echo json_encode($object, JSON_PRETTY_PRINT);

For html output:
<pre>
<?php echo nl2br(json_encode($yourArrayOrObject, JSON_PRETTY_PRINT)); ?>
</pre>

If you have an already json encoded string, then you need to use
json_decode to get an object and then encode the object to prettify the
json.

> [{"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":"dog@nk.ca","phone":"7809999999"}}],[{"billing_details":{"address_1":"","city":"","province":"","country":"CA","postal_code":""}}]]
>
> How can I carefully strip unnecessary punctuation?

The unnecessary [] that you get is for you use an array to store things
inside, use a class object instead.

Here is a small example, where only the cart is an array in the json:

--- start of php ---
$a = new class{};
$a->store_id = "123";
$a->api_token = "432";
$a->cart = array();
// add item to cart that cast an array to object
$a->cart[] = (object)[ "value" => "12.01", "item" => "banana" ];
// add item to cat that is an undefined object
$itemObj = new class{};
$itemObj->value = "10.02";
$itemObj->item = "apple";
$a->cart[] = $itemObj;
echo json_encode($a, JSON_PRETTY_PRINT);
--- eof ---

Only use array when you are to have a collection of items, for example a
shopping cart, but do not use array when you have a single item, then
better to use an object of some sort, for your example I would actually
create classes that describes the json, you will of course have nested
objects in the end.

--
//Aho

Re: Stripping a JSON of extra characters in PHP

<87a61rq171.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=795&group=comp.lang.php#795

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Sun, 05 Feb 2023 20:58:26 +0000
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <87a61rq171.fsf@bsb.me.uk>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <875yclmkpv.fsf@bsb.me.uk>
<k44tjfFku3dU3@mid.individual.net> <87ilgis3p2.fsf@bsb.me.uk>
<k4881fF6dctU1@mid.individual.net> <87edr5q8lu.fsf@bsb.me.uk>
<k49ojdFdcn7U1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="5975cb4157a41d16b46a615111281563";
logging-data="2834364"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NQe8bBPJggEYASk5K12Ml1SkSxsVx3fM="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:ruOCwJoePeaPnn0+NIuV9Gh/rog=
sha1:8jPD++5t+ZXdRffS7Rzbac8tc2M=
X-BSB-Auth: 1.e74de488113e75d9c416.20230205205826GMT.87a61rq171.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 5 Feb 2023 20:58 UTC

Arno Welzel <usenet@arnowelzel.de> writes:

> Ben Bacarisse, 2023-02-05 01:06:
>
>> Arno Welzel <usenet@arnowelzel.de> writes:
> [...]
>>> Then you could have seen, that the invalid example only
>>> missed a comma.
>>
>> Yes, I spotted that too. You'll never guess how...
>
> Well, then I wonder why you just wrote this:
>
> "But that one is (a) valid and (b) has no unnecessary punctuation, so I
> don't know what it is you mean."

Because "that one" (the second sample shown) was (a) valid and (b) had
no unnecessary punctuation. As result, I could not tell what the OP
meant by their question. What's bothering you about this?

--
Ben.

Re: Stripping a JSON of extra characters in PHP

<k4apg1FibpsU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=796&group=comp.lang.php#796

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@arnowelzel.de (Arno Welzel)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Sun, 5 Feb 2023 23:38:57 +0100
Lines: 29
Message-ID: <k4apg1FibpsU1@mid.individual.net>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <875yclmkpv.fsf@bsb.me.uk>
<k44tjfFku3dU3@mid.individual.net> <87ilgis3p2.fsf@bsb.me.uk>
<k4881fF6dctU1@mid.individual.net> <87edr5q8lu.fsf@bsb.me.uk>
<k49ojdFdcn7U1@mid.individual.net> <87a61rq171.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: individual.net J86XJP0ywLfmna/Hfql4sgjseQM0H8oNMXkMVGYqO0vO4uy1v1
Cancel-Lock: sha1:OLJIUdhAORRDdbJSSchRBD7AlUw=
Content-Language: de-DE
In-Reply-To: <87a61rq171.fsf@bsb.me.uk>
 by: Arno Welzel - Sun, 5 Feb 2023 22:38 UTC

Ben Bacarisse, 2023-02-05 21:58:

> Arno Welzel <usenet@arnowelzel.de> writes:
>
>> Ben Bacarisse, 2023-02-05 01:06:
>>
>>> Arno Welzel <usenet@arnowelzel.de> writes:
>> [...]
>>>> Then you could have seen, that the invalid example only
>>>> missed a comma.
>>>
>>> Yes, I spotted that too. You'll never guess how...
>>
>> Well, then I wonder why you just wrote this:
>>
>> "But that one is (a) valid and (b) has no unnecessary punctuation, so I
>> don't know what it is you mean."
>
> Because "that one" (the second sample shown) was (a) valid and (b) had
> no unnecessary punctuation. As result, I could not tell what the OP
> meant by their question. What's bothering you about this?

Just read my other posts about this, maybe you get it. If not, it's ok
as well.

--
Arno Welzel
https://arnowelzel.de

Re: Stripping a JSON of extra characters in PHP

<trpl8k$12si$72@gallifrey.nk.ca>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=797&group=comp.lang.php#797

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.nk.ca!.POSTED.doctor.nl2k.ab.ca!not-for-mail
From: doctor@doctor.nl2k.ab.ca (The Doctor)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Mon, 6 Feb 2023 01:31:00 -0000 (UTC)
Organization: NetKnow News
Message-ID: <trpl8k$12si$72@gallifrey.nk.ca>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <k49veoF1ne8U3@mid.individual.net>
Injection-Date: Mon, 6 Feb 2023 01:31:00 -0000 (UTC)
Injection-Info: gallifrey.nk.ca; posting-host="doctor.nl2k.ab.ca:204.209.81.1";
logging-data="35730"; mail-complaints-to="usenet@gallifrey.nk.ca"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: doctor@doctor.nl2k.ab.ca (The Doctor)
 by: The Doctor - Mon, 6 Feb 2023 01:31 UTC

In article <k49veoF1ne8U3@mid.individual.net>,
J.O. Aho <user@example.net> wrote:
>On 01/02/2023 16:45, The Doctor wrote:
>> From https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
>>
>> I need a JSON as follows:
>>
>> {
>> "store_id":"moneris",
>> "api_token":"hurgle",
>
>For console output:
>echo json_encode($object, JSON_PRETTY_PRINT);
>
>For html output:
><pre>
><?php echo nl2br(json_encode($yourArrayOrObject, JSON_PRETTY_PRINT)); ?>
></pre>
>
>If you have an already json encoded string, then you need to use
>json_decode to get an object and then encode the object to prettify the
>json.
>
>
>>
>[{"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":"dog@nk.ca","phone":"7809999999"}}],[{"billing_details":{"address_1":"","city":"","province":"","country":"CA","postal_code":""}}]]
>>
>> How can I carefully strip unnecessary punctuation?
>
>The unnecessary [] that you get is for you use an array to store things
>inside, use a class object instead.
>
>Here is a small example, where only the cart is an array in the json:
>
>--- start of php ---
>$a = new class{};
>$a->store_id = "123";
>$a->api_token = "432";
>$a->cart = array();
>// add item to cart that cast an array to object
>$a->cart[] = (object)[ "value" => "12.01", "item" => "banana" ];
>// add item to cat that is an undefined object
>$itemObj = new class{};
>$itemObj->value = "10.02";
>$itemObj->item = "apple";
>$a->cart[] = $itemObj;
>echo json_encode($a, JSON_PRETTY_PRINT);
>--- eof ---
>
>Only use array when you are to have a collection of items, for example a
>shopping cart, but do not use array when you have a single item, then
>better to use an object of some sort, for your example I would actually
>create classes that describes the json, you will of course have nested
>objects in the end.
>
>--

And in the case of recurring items when being puleld from
a form getting parsed?

> //Aho
>
>

--
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b
If their only strength is in enforcing weakness, then they will preside over ruin. -unknown Beware https://mindspring.com

Re: Stripping a JSON of extra characters in PHP

<k4bnmkFffdeU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=798&group=comp.lang.php#798

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: user@example.net (J.O. Aho)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Mon, 6 Feb 2023 08:14:28 +0100
Lines: 29
Message-ID: <k4bnmkFffdeU1@mid.individual.net>
References: <tre1ei$2lti$75@gallifrey.nk.ca>
<k49veoF1ne8U3@mid.individual.net> <trpl8k$12si$72@gallifrey.nk.ca>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net Kk/3+44KY9Zh2MgRyBq49w3kvc9L1ab2B4wLVnzJSSPbeYjbyn
Cancel-Lock: sha1:HkAAEk00+kStqtS9DZHI6lWz2uo=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.7.1
Content-Language: en-US-large
In-Reply-To: <trpl8k$12si$72@gallifrey.nk.ca>
 by: J.O. Aho - Mon, 6 Feb 2023 07:14 UTC

On 06/02/2023 02:31, The Doctor wrote:
> And in the case of recurring items when being puleld from
> a form getting parsed?

If you are thinking of post value which is an array, then the simplest
would be:
$a->cart = (object)$_POST['cart']; // this may give you object you don't
want

Just keep in mind that the data is unsafe to use, you should do the long
way and validate the data and as you validate you can then add the
values to a temp variable and if all the cart items passes validation,
then add it to the main json object (in this silly example the $a).

If you get a new cart posted (updates), then replace the current one
you have in the session, don't forget to validate the data before you
replace the cart section. Only have the latest validated one
$a->cart = $validated_shopping_cart; // validated_shopping_cart is a
json object

for duplicate entries you have to decide what to do, cast an error or
merge them together, that is up to you, but do not have duplicate items
in your json object.

I hope that was the answer you was looking for.

--
//Aho

Re: Stripping a JSON of extra characters in PHP

<trr6aj$1v6p$58@gallifrey.nk.ca>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=799&group=comp.lang.php#799

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.nk.ca!.POSTED.doctor.nl2k.ab.ca!not-for-mail
From: doctor@doctor.nl2k.ab.ca (The Doctor)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Mon, 6 Feb 2023 15:28:19 -0000 (UTC)
Organization: NetKnow News
Message-ID: <trr6aj$1v6p$58@gallifrey.nk.ca>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <k49veoF1ne8U3@mid.individual.net> <trpl8k$12si$72@gallifrey.nk.ca> <k4bnmkFffdeU1@mid.individual.net>
Injection-Date: Mon, 6 Feb 2023 15:28:19 -0000 (UTC)
Injection-Info: gallifrey.nk.ca; posting-host="doctor.nl2k.ab.ca:204.209.81.1";
logging-data="64729"; mail-complaints-to="usenet@gallifrey.nk.ca"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: doctor@doctor.nl2k.ab.ca (The Doctor)
 by: The Doctor - Mon, 6 Feb 2023 15:28 UTC

In article <k4bnmkFffdeU1@mid.individual.net>,
J.O. Aho <user@example.net> wrote:
>On 06/02/2023 02:31, The Doctor wrote:
>> And in the case of recurring items when being puleld from
>> a form getting parsed?
>
>If you are thinking of post value which is an array, then the simplest
>would be:
>$a->cart = (object)$_POST['cart']; // this may give you object you don't
>want
>
>Just keep in mind that the data is unsafe to use, you should do the long
>way and validate the data and as you validate you can then add the
>values to a temp variable and if all the cart items passes validation,
>then add it to the main json object (in this silly example the $a).
>
>If you get a new cart posted (updates), then replace the current one
>you have in the session, don't forget to validate the data before you
>replace the cart section. Only have the latest validated one
>$a->cart = $validated_shopping_cart; // validated_shopping_cart is a
>json object
>
>for duplicate entries you have to decide what to do, cast an error or
>merge them together, that is up to you, but do not have duplicate items
>in your json object.
>
>I hope that was the answer you was looking for.
>

The cart is being derived from a previous form being passed into PHP!

Just an update

<?=session_start();
error_reporting(E_ALL);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
</head>
<?php
if(!empty($_SESSION['sessiondata'])){
}
?>
<?php
$myObj = [];
$cart = [];
$items = [];
$itemssubarray = [];
$storevalues= [];
$contact_details=[];
$shipping_details=[];
$billing_details=[];
$arr2 =array();

$items_count = 0;
$newtotal = 0;
$subtotal = 0;
$arr = array();
if (isset($_POST["submit"])){

$arr=array(
'store_id' => "store3",
'api_token' => "yesguy",
'checkout_id' => "chktGLFZQtore3",
'txn_total' => $_POST['charge_total'],
'environment' => "qa",
'action' => "preload",
'cart' => array(
(foreach ($_POST['quantity'] as $key => $value) {

if( $value > 0){

if(isset($_POST['with_gst'][$key])){
$unit_cost = 63.00;
}else{
$unit_cost = 60.00; //no gst included
}

$subtotal = ($unit_cost * $value);
$quantity = ($value);

$cart['items'][] =array(
'url' => "https://www.pdsolutions.ca/images/newwhiteheader.png",
'description' => $_POST['description'][$key],
'product_code' => $_POST['id'][$key],
'unit_cost' => $unit_cost,
'quantity' => $quantity,
),
$newtotal += $subtotal;
$items_count++;
array_push(items,itemsubarray);
}
}

'subtotal' => $newtotal,
if(isset($_POST['with_gst'][$key])){
'tax'=>array(
'amount' => ($newtotal * 0.05),
'description' => "GST",
'rate' => "5.00",
),
})
),
'contact_details'=>array(
'first_name' =>$_POST['bill_first_name'],
'last_name' => $_POST['bill_last_name'],
'email' => $_POST['email'],
'phone' => $_POST['bill_phone'],
),
'billing_details'=>array(
'address_1' => $_POST['bill_address_one'],
'city' => $_POST['bill_city'],
'province' => $_POST['bill_state_or_province'],
'country' => "CA",
'postal_code' => $_POST['bill_postal_code'],
),

);

}

// $billing_details[] = array (
// "billing_details"=>array(
//'address_1' => $_POST['bill_address_one'],
//'city' => $_POST['bill_city'],
//'province' => $_POST['bill_state_or_province'],
//'country' => "CA",
//'postal_code' => $_POST['bill_postal_code'],

// )

$myObj = $arr;
$myJSON = json_encode($myObj);

echo $myJSON;

// Prepare new cURL resource
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://gatewayt.moneris.com/chkt/request/request.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $myJSON);
$array_length = count($arr, COUNT_RECURSIVE);
// Set HTTP Header for POST request
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json' ,'Content-Length: ' . strlen($myJSON)
)
);

// Submit the POST request
$result = curl_exec($ch);
// Close cURL session handle
curl_close($ch);
print_r($arr);
print_r($result);
$response_data = json_decode($result);
print_r($response_data);

$result_data = json_decode($result, true);
print_r($result_data);
if( isset($result_data['response']['error']) && ( ! (bool) $result_data['response']['success'] ) ){
echo 'error message';
} $token = $result_data['response']['ticket'];
?>

<body>
<div id="outerDiv" style="width:400px;height:300px">
<div id="monerisCheckout"></div>
</div>

<script src="https://gatewayt.moneris.com/chktv2/js/chkt_v2.00.js"></script>
<script>
let myCheckout = new monerisCheckout();
myCheckout.setMode("qa");
myCheckout.setCheckoutDiv("monerisCheckout");
myCheckout.setCallback("page_loaded", testPageLoad);
myCheckout.setCallback("payment_receipt", testPayReceipt);
myCheckout.setCallback("payment_complete", testPayComplete);
myCheckout.setCallback("cancel_transaction", testCancel);
myCheckout.setCallback("error_event", testCancel);
myCheckout.setCallback("payment_submitted", testPaymentSubmitted);
myCheckout.startCheckout('<?php echo $token ?>');
myCheckout.setCallback("page_closed", testCancel);

function testPageLoad(res){

console.log(res)

}

function testPaySubmit(res){

console.log(res)

}

function testPayReceipt(res){

console.log(res)

}

function testPayComplete(res){

console.log(res)

}

function testPaymentSubmitted(res){

console.log(res)

}

function testCancel(res){

console.log(res)

//myCheckout.closeCheckout(JSON.parse(res).ticket)

}



</script>
</body>
</html>

75% is working properly.

The cart section is now an issue .

>--
> //Aho
>

--
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b
If their only strength is in enforcing weakness, then they will preside over ruin. -unknown Beware https://mindspring.com

Re: Stripping a JSON of extra characters in PHP

<k4cqqvFpoj5U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=800&group=comp.lang.php#800

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: user@example.net (J.O. Aho)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Mon, 6 Feb 2023 18:14:07 +0100
Lines: 153
Message-ID: <k4cqqvFpoj5U1@mid.individual.net>
References: <tre1ei$2lti$75@gallifrey.nk.ca>
<k49veoF1ne8U3@mid.individual.net> <trpl8k$12si$72@gallifrey.nk.ca>
<k4bnmkFffdeU1@mid.individual.net> <trr6aj$1v6p$58@gallifrey.nk.ca>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net LizIUP3gHCt8U2NbWCJF4AgF0PVsQyj/HO/bRb0mnZ2vHhO0Zo
Cancel-Lock: sha1:rmADRFdRTs1EkybvKMXhcZ3uoKA=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.7.1
Content-Language: en-US-large
In-Reply-To: <trr6aj$1v6p$58@gallifrey.nk.ca>
 by: J.O. Aho - Mon, 6 Feb 2023 17:14 UTC

On 2/6/23 16:28, The Doctor wrote:
> In article <k4bnmkFffdeU1@mid.individual.net>,
> J.O. Aho <user@example.net> wrote:
>> On 06/02/2023 02:31, The Doctor wrote:
>>> And in the case of recurring items when being puleld from
>>> a form getting parsed?
>>
>> If you are thinking of post value which is an array, then the simplest
>> would be:
>> $a->cart = (object)$_POST['cart']; // this may give you object you don't
>> want
>>
>> Just keep in mind that the data is unsafe to use, you should do the long
>> way and validate the data and as you validate you can then add the
>> values to a temp variable and if all the cart items passes validation,
>> then add it to the main json object (in this silly example the $a).
>>
>> If you get a new cart posted (updates), then replace the current one
>> you have in the session, don't forget to validate the data before you
>> replace the cart section. Only have the latest validated one
>> $a->cart = $validated_shopping_cart; // validated_shopping_cart is a
>> json object
>>
>> for duplicate entries you have to decide what to do, cast an error or
>> merge them together, that is up to you, but do not have duplicate items
>> in your json object.
>>
>> I hope that was the answer you was looking for.
>>
>
> The cart is being derived from a previous form being passed into PHP!
>
>
> Just an update
> The cart section is now an issue .
>

> 'cart' => array(
> (foreach ($_POST['quantity'] as $key => $value) {
>
> if( $value > 0){
>
> if(isset($_POST['with_gst'][$key])){
> $unit_cost = 63.00;
> }else{
> $unit_cost = 60.00; //no gst included
> }
>
> $subtotal = ($unit_cost * $value);
> $quantity = ($value);
>
> $cart['items'][] =array(
> 'url' => "https://www.pdsolutions.ca/images/newwhiteheader.png",
> 'description' => $_POST['description'][$key],
> 'product_code' => $_POST['id'][$key],
> 'unit_cost' => $unit_cost,
> 'quantity' => $quantity,
> ),
> $newtotal += $subtotal;
> $items_count++;
> array_push(items,itemsubarray);
> }
> }
>
> 'subtotal' => $newtotal,
> if(isset($_POST['with_gst'][$key])){
> 'tax'=>array(
> 'amount' => ($newtotal * 0.05),
> 'description' => "GST",
> 'rate' => "5.00",
> ),
> })
> ),

It's messy and a lot of hard coded things and I'm just guessing what you
try to do, I think I would have done things differently, for example
posting all the data maybe as a serialized json object from the client
side, I would fetch the items value from the database together with
description, I would have the tax rate in the database too, easy to
change the the tax in the database when the the government changes it.

I made an small example that take the cart part, not sure if it's what
you want to have, but at least should give you some idea and the reason
I didn't use $_POST values is that it's easier to test things when you
can modify values based on what you want and fine tune things till they
are right, then you can modify the constructor to not take any
arguments, I would make the "cart" class to hold all the values you need
for your json.
If you need to use values between functions, then use private, for then
they will not be included when you use the json_encode()

--- simple example ---
<?php

class cart {
public $total = 0;
public $items = [];
private $uber = "man"; // this will not be included in the json output

public function __construct($quantityArray, $gstArray, $descArray,
$idArray) {
foreach($quantityArray as $key => $num_items)
{
if($num_items == 0)
continue;

$has_tax = isset($gstArray[$key]);
$unit_cost = $has_tax ? 63 : 60;
$sub_total = $num_items * $unit_cost;
$this->total = $sub_total;

$item = [
'url' =>
'https://www.pdsolutions.ca/images/newwhiteheader.png',
'description' => $descArray[$key],
'product_code' => $idArray[$key],
'unit_cost' => number_format($unit_cost, 2),
'quantity' => $num_items,
'subtotal' => number_format($sub_total, 2),
];

if($has_tax) {
$item['tax'] = (object)[ 'amount' =>
number_format($sub_total * 0.05), 'description' => "GST", 'rate' =>
'5.00' ];
}

$this->items[] = (object)$item;

}
}
}

$q = [1, 2, 0];
$g = [1, 1, 0];
$d = ['banana', 'apple', 'car'];
$i = [22, 11, 33];

$cart = new cart($q, $g, $d, $i);
echo json_encode($cart, JSON_PRETTY_PRINT);
?>
--- eof ---

You can also see the use of number_format(), that just so we get the
right number of decimals, I haven't bothered about rounding which would
be sane. And it's the "items" that should be something similar to your cart.

--

//Aho

Re: Stripping a JSON of extra characters in PHP

<k4d3dvFtd5nU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=801&group=comp.lang.php#801

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@arnowelzel.de (Arno Welzel)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Mon, 6 Feb 2023 20:40:47 +0100
Lines: 33
Message-ID: <k4d3dvFtd5nU1@mid.individual.net>
References: <tre1ei$2lti$75@gallifrey.nk.ca>
<k49veoF1ne8U3@mid.individual.net> <trpl8k$12si$72@gallifrey.nk.ca>
<k4bnmkFffdeU1@mid.individual.net> <trr6aj$1v6p$58@gallifrey.nk.ca>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: individual.net 0VuHJdgBjxB9Yjp4EvwzwQHdUGl2RLxj9akMbuWG6fdzig0h1W
Cancel-Lock: sha1:gvRoyRusAod47IUVDXqZxOUbdzU=
Content-Language: de-DE
In-Reply-To: <trr6aj$1v6p$58@gallifrey.nk.ca>
 by: Arno Welzel - Mon, 6 Feb 2023 19:40 UTC

The Doctor, 2023-02-06 16:28:

[...]
> The cart is being derived from a previous form being passed into PHP!

[...]
> $arr=array(
> 'store_id' => "store3",
> 'api_token' => "yesguy",
> 'checkout_id' => "chktGLFZQtore3",
> 'txn_total' => $_POST['charge_total'],
> 'environment' => "qa",
> 'action' => "preload",
> 'cart' => array(
> (foreach ($_POST['quantity'] as $key => $value) {

Well - this will result in an array in the JSON named "cart".

> $cart['items'][] =array(

And this will also become an array named "items" inside "cart".

So if you don't want "cart" to be an array in the JSON, then don't
create it this way.

Learn how to read JSON and that the "punctuation" are not just
characters but have a specific meaning. In this case you created an
array and the JSON will have an array as well - indicated by "[" and "]".

--
Arno Welzel
https://arnowelzel.de

Re: Stripping a JSON of extra characters in PHP

<trs7ki$2pkv$28@gallifrey.nk.ca>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=802&group=comp.lang.php#802

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.nk.ca!.POSTED.doctor.nl2k.ab.ca!not-for-mail
From: doctor@doctor.nl2k.ab.ca (The Doctor)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Tue, 7 Feb 2023 00:56:50 -0000 (UTC)
Organization: NetKnow News
Message-ID: <trs7ki$2pkv$28@gallifrey.nk.ca>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <k4bnmkFffdeU1@mid.individual.net> <trr6aj$1v6p$58@gallifrey.nk.ca> <k4cqqvFpoj5U1@mid.individual.net>
Injection-Date: Tue, 7 Feb 2023 00:56:50 -0000 (UTC)
Injection-Info: gallifrey.nk.ca; posting-host="doctor.nl2k.ab.ca:204.209.81.1";
logging-data="91807"; mail-complaints-to="usenet@gallifrey.nk.ca"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: doctor@doctor.nl2k.ab.ca (The Doctor)
 by: The Doctor - Tue, 7 Feb 2023 00:56 UTC

In article <k4cqqvFpoj5U1@mid.individual.net>,
J.O. Aho <user@example.net> wrote:
>On 2/6/23 16:28, The Doctor wrote:
>> In article <k4bnmkFffdeU1@mid.individual.net>,
>> J.O. Aho <user@example.net> wrote:
>>> On 06/02/2023 02:31, The Doctor wrote:
>>>> And in the case of recurring items when being puleld from
>>>> a form getting parsed?
>>>
>>> If you are thinking of post value which is an array, then the simplest
>>> would be:
>>> $a->cart = (object)$_POST['cart']; // this may give you object you don't
>>> want
>>>
>>> Just keep in mind that the data is unsafe to use, you should do the long
>>> way and validate the data and as you validate you can then add the
>>> values to a temp variable and if all the cart items passes validation,
>>> then add it to the main json object (in this silly example the $a).
>>>
>>> If you get a new cart posted (updates), then replace the current one
>>> you have in the session, don't forget to validate the data before you
>>> replace the cart section. Only have the latest validated one
>>> $a->cart = $validated_shopping_cart; // validated_shopping_cart is a
>>> json object
>>>
>>> for duplicate entries you have to decide what to do, cast an error or
>>> merge them together, that is up to you, but do not have duplicate items
>>> in your json object.
>>>
>>> I hope that was the answer you was looking for.
>>>
>>
>> The cart is being derived from a previous form being passed into PHP!
>>
>>
>> Just an update
>> The cart section is now an issue .
>>
>
>> 'cart' => array(
>> (foreach ($_POST['quantity'] as $key => $value) {
>>
>> if( $value > 0){
>>
>> if(isset($_POST['with_gst'][$key])){
>> $unit_cost = 63.00;
>> }else{
>> $unit_cost = 60.00; //no gst included
>> }
>>
>> $subtotal = ($unit_cost * $value);
>> $quantity = ($value);
>>
>> $cart['items'][] =array(
>> 'url' => "https://www.pdsolutions.ca/images/newwhiteheader.png",
>> 'description' => $_POST['description'][$key],
>> 'product_code' => $_POST['id'][$key],
>> 'unit_cost' => $unit_cost,
>> 'quantity' => $quantity,
>> ),
>> $newtotal += $subtotal;
>> $items_count++;
>> array_push(items,itemsubarray);
>> }
>> }
>>
>> 'subtotal' => $newtotal,
>> if(isset($_POST['with_gst'][$key])){
>> 'tax'=>array(
>> 'amount' => ($newtotal * 0.05),
>> 'description' => "GST",
>> 'rate' => "5.00",
>> ),
>> })
>> ),
>
>It's messy and a lot of hard coded things and I'm just guessing what you
>try to do, I think I would have done things differently, for example
>posting all the data maybe as a serialized json object from the client
>side, I would fetch the items value from the database together with
>description, I would have the tax rate in the database too, easy to
>change the the tax in the database when the the government changes it.
>
>I made an small example that take the cart part, not sure if it's what
>you want to have, but at least should give you some idea and the reason
>I didn't use $_POST values is that it's easier to test things when you
>can modify values based on what you want and fine tune things till they
>are right, then you can modify the constructor to not take any
>arguments, I would make the "cart" class to hold all the values you need
>for your json.
>If you need to use values between functions, then use private, for then
>they will not be included when you use the json_encode()
>
>--- simple example ---
><?php
>
>class cart {
> public $total = 0;
> public $items = [];
> private $uber = "man"; // this will not be included in the json output
>
> public function __construct($quantityArray, $gstArray, $descArray,
>$idArray) {
> foreach($quantityArray as $key => $num_items)
> {
> if($num_items == 0)
> continue;
>
> $has_tax = isset($gstArray[$key]);
> $unit_cost = $has_tax ? 63 : 60;
> $sub_total = $num_items * $unit_cost;
> $this->total = $sub_total;
>
> $item = [
> 'url' =>
>'https://www.pdsolutions.ca/images/newwhiteheader.png',
> 'description' => $descArray[$key],
> 'product_code' => $idArray[$key],
> 'unit_cost' => number_format($unit_cost, 2),
> 'quantity' => $num_items,
> 'subtotal' => number_format($sub_total, 2),
> ];
>
> if($has_tax) {
> $item['tax'] = (object)[ 'amount' =>
>number_format($sub_total * 0.05), 'description' => "GST", 'rate' =>
>'5.00' ];
> }
>
> $this->items[] = (object)$item;
>
> }
> }
>}
>
>$q = [1, 2, 0];
>$g = [1, 1, 0];
>$d = ['banana', 'apple', 'car'];
>$i = [22, 11, 33];
>
>$cart = new cart($q, $g, $d, $i);
>echo json_encode($cart, JSON_PRETTY_PRINT);
>?>
>--- eof ---
>
>You can also see the use of number_format(), that just so we get the
>right number of decimals, I haven't bothered about rounding which would
>be sane. And it's the "items" that should be something similar to your cart.
>
>--
>
> //Aho
>
>
>

Will try. Basing this in the Moneris docs.
--
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b
Extremism is for those who love judging, and care nothing for accuracy. -unknown Beware https://mindspring.com

Re: Stripping a JSON of extra characters in PHP

<trs7m0$2pkv$29@gallifrey.nk.ca>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=803&group=comp.lang.php#803

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.nk.ca!.POSTED.doctor.nl2k.ab.ca!not-for-mail
From: doctor@doctor.nl2k.ab.ca (The Doctor)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Tue, 7 Feb 2023 00:57:36 -0000 (UTC)
Organization: NetKnow News
Message-ID: <trs7m0$2pkv$29@gallifrey.nk.ca>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <k4bnmkFffdeU1@mid.individual.net> <trr6aj$1v6p$58@gallifrey.nk.ca> <k4d3dvFtd5nU1@mid.individual.net>
Injection-Date: Tue, 7 Feb 2023 00:57:36 -0000 (UTC)
Injection-Info: gallifrey.nk.ca; posting-host="doctor.nl2k.ab.ca:204.209.81.1";
logging-data="91807"; mail-complaints-to="usenet@gallifrey.nk.ca"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: doctor@doctor.nl2k.ab.ca (The Doctor)
 by: The Doctor - Tue, 7 Feb 2023 00:57 UTC

In article <k4d3dvFtd5nU1@mid.individual.net>,
Arno Welzel <usenet@arnowelzel.de> wrote:
>The Doctor, 2023-02-06 16:28:
>
>[...]
>> The cart is being derived from a previous form being passed into PHP!
>
>[...]
>> $arr=array(
>> 'store_id' => "store3",
>> 'api_token' => "yesguy",
>> 'checkout_id' => "chktGLFZQtore3",
>> 'txn_total' => $_POST['charge_total'],
>> 'environment' => "qa",
>> 'action' => "preload",
>> 'cart' => array(
>> (foreach ($_POST['quantity'] as $key => $value) {
>
>Well - this will result in an array in the JSON named "cart".
>
>> $cart['items'][] =array(
>
>And this will also become an array named "items" inside "cart".
>
>So if you don't want "cart" to be an array in the JSON, then don't
>create it this way.
>
>Learn how to read JSON and that the "punctuation" are not just
>characters but have a specific meaning. In this case you created an
>array and the JSON will have an array as well - indicated by "[" and "]".
>

Again basing this on Moneris prereqs.

>--
>Arno Welzel
>https://arnowelzel.de
>

--
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b
Extremism is for those who love judging, and care nothing for accuracy. -unknown Beware https://mindspring.com

Re: Stripping a JSON of extra characters in PHP

<trs9fn$ak$1@gallifrey.nk.ca>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=804&group=comp.lang.php#804

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.nk.ca!.POSTED.doctor.nl2k.ab.ca!not-for-mail
From: doctor@doctor.nl2k.ab.ca (The Doctor)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Tue, 7 Feb 2023 01:28:23 -0000 (UTC)
Organization: NetKnow News
Message-ID: <trs9fn$ak$1@gallifrey.nk.ca>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <trr6aj$1v6p$58@gallifrey.nk.ca> <k4d3dvFtd5nU1@mid.individual.net> <trs7m0$2pkv$29@gallifrey.nk.ca>
Injection-Date: Tue, 7 Feb 2023 01:28:23 -0000 (UTC)
Injection-Info: gallifrey.nk.ca; posting-host="doctor.nl2k.ab.ca:204.209.81.1";
logging-data="340"; mail-complaints-to="usenet@gallifrey.nk.ca"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: doctor@doctor.nl2k.ab.ca (The Doctor)
 by: The Doctor - Tue, 7 Feb 2023 01:28 UTC

In article <trs7m0$2pkv$29@gallifrey.nk.ca>,
The Doctor <doctor@doctor.nl2k.ab.ca> wrote:
>In article <k4d3dvFtd5nU1@mid.individual.net>,
>Arno Welzel <usenet@arnowelzel.de> wrote:
>>The Doctor, 2023-02-06 16:28:
>>
>>[...]
>>> The cart is being derived from a previous form being passed into PHP!
>>
>>[...]
>>> $arr=array(
>>> 'store_id' => "store3",
>>> 'api_token' => "yesguy",
>>> 'checkout_id' => "chktGLFZQtore3",
>>> 'txn_total' => $_POST['charge_total'],
>>> 'environment' => "qa",
>>> 'action' => "preload",
>>> 'cart' => array(
>>> (foreach ($_POST['quantity'] as $key => $value) {
>>
>>Well - this will result in an array in the JSON named "cart".
>>
>>> $cart['items'][] =array(
>>
>>And this will also become an array named "items" inside "cart".
>>
>>So if you don't want "cart" to be an array in the JSON, then don't
>>create it this way.
>>
>>Learn how to read JSON and that the "punctuation" are not just
>>characters but have a specific meaning. In this case you created an
>>array and the JSON will have an array as well - indicated by "[" and "]".
>>
>
>Again basing this on Moneris prereqs.
>

cart is subarray with the main array, added items in the cart
is a subarray of the cart.

Source

https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet

>>--
>>Arno Welzel
>>https://arnowelzel.de
>>
>
>
>--
>Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
>Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
>Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b
>Extremism is for those who love judging, and care nothing for accuracy.
>-unknown Beware https://mindspring.com

--
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b
Extremism is for those who love judging, and care nothing for accuracy. -unknown Beware https://mindspring.com

Re: Stripping a JSON of extra characters in PHP

<k4efhpF59f9U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=805&group=comp.lang.php#805

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@arnowelzel.de (Arno Welzel)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Tue, 7 Feb 2023 09:13:47 +0100
Lines: 47
Message-ID: <k4efhpF59f9U1@mid.individual.net>
References: <tre1ei$2lti$75@gallifrey.nk.ca>
<k4bnmkFffdeU1@mid.individual.net> <trr6aj$1v6p$58@gallifrey.nk.ca>
<k4d3dvFtd5nU1@mid.individual.net> <trs7m0$2pkv$29@gallifrey.nk.ca>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: individual.net 4yTHoU00tjhSJxT+otr1EglYYiejoG23YvPJJiLxQHTcMyuHAM
Cancel-Lock: sha1:9NVYizytcAlo64EPieYaUwt7Ues=
Content-Language: de-DE
In-Reply-To: <trs7m0$2pkv$29@gallifrey.nk.ca>
 by: Arno Welzel - Tue, 7 Feb 2023 08:13 UTC

The Doctor, 2023-02-07 01:57:

> In article <k4d3dvFtd5nU1@mid.individual.net>,
> Arno Welzel <usenet@arnowelzel.de> wrote:
>> The Doctor, 2023-02-06 16:28:
>>
>> [...]
>>> The cart is being derived from a previous form being passed into PHP!
>>
>> [...]
>>> $arr=array(
>>> 'store_id' => "store3",
>>> 'api_token' => "yesguy",
>>> 'checkout_id' => "chktGLFZQtore3",
>>> 'txn_total' => $_POST['charge_total'],
>>> 'environment' => "qa",
>>> 'action' => "preload",
>>> 'cart' => array(
>>> (foreach ($_POST['quantity'] as $key => $value) {
>>
>> Well - this will result in an array in the JSON named "cart".
>>
>>> $cart['items'][] =array(
>>
>> And this will also become an array named "items" inside "cart".
>>
>> So if you don't want "cart" to be an array in the JSON, then don't
>> create it this way.
>>
>> Learn how to read JSON and that the "punctuation" are not just
>> characters but have a specific meaning. In this case you created an
>> array and the JSON will have an array as well - indicated by "[" and "]".
>>
>
> Again basing this on Moneris prereqs.

What is "Moneris prereqs"?

Your OP was: "How can I carefully strip unnecessary punctuation?" I
tried to explain to you, where these "punctuation" comes from. But if
you don't accept the facts, then you have to live with it.

--
Arno Welzel
https://arnowelzel.de

Re: Stripping a JSON of extra characters in PHP

<k4efniF59f9U2@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=806&group=comp.lang.php#806

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@arnowelzel.de (Arno Welzel)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Tue, 7 Feb 2023 09:16:52 +0100
Lines: 33
Message-ID: <k4efniF59f9U2@mid.individual.net>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <trr6aj$1v6p$58@gallifrey.nk.ca>
<k4d3dvFtd5nU1@mid.individual.net> <trs7m0$2pkv$29@gallifrey.nk.ca>
<trs9fn$ak$1@gallifrey.nk.ca>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: individual.net cjmFcsBlga+9ibtJ6ctccwESSRS5Wa+naT7WWHJySD1QPfju89
Cancel-Lock: sha1:HE+/ToL/LSyBPg8JnnsLMW1scQU=
Content-Language: de-DE
In-Reply-To: <trs9fn$ak$1@gallifrey.nk.ca>
 by: Arno Welzel - Tue, 7 Feb 2023 08:16 UTC

The Doctor, 2023-02-07 02:28:

[...]
> cart is subarray with the main array, added items in the cart
> is a subarray of the cart.>
> Source
>
> https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet

No! Cart is an OBJECT there:

"cart":{
....
}

Also contact details:

"contact_details":{
....
}

The "{" indicates the beginning of an OBJECT while "[" starts an ARRAY.

As I said: learn how to read JSON and try to understand how that format
works!

Also see: <https://www.json.org/json-en.html>

--
Arno Welzel
https://arnowelzel.de

Re: Stripping a JSON of extra characters in PHP

<k4egigF59f9U3@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=807&group=comp.lang.php#807

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@arnowelzel.de (Arno Welzel)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Tue, 7 Feb 2023 09:31:14 +0100
Lines: 137
Message-ID: <k4egigF59f9U3@mid.individual.net>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <trr6aj$1v6p$58@gallifrey.nk.ca>
<k4d3dvFtd5nU1@mid.individual.net> <trs7m0$2pkv$29@gallifrey.nk.ca>
<trs9fn$ak$1@gallifrey.nk.ca> <k4efniF59f9U2@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: individual.net obw1RiizYdOFvCO0oInzugTqyj61WjjivBC7bQImg3sd1x7qe7
Cancel-Lock: sha1:4+2bWOalZURgCovEhibzJ7ifmU8=
Content-Language: de-DE
In-Reply-To: <k4efniF59f9U2@mid.individual.net>
 by: Arno Welzel - Tue, 7 Feb 2023 08:31 UTC

Arno Welzel, 2023-02-07 09:16:

> The Doctor, 2023-02-07 02:28:
>
> [...]
>> cart is subarray with the main array, added items in the cart
>> is a subarray of the cart.>
>> Source
>>
>> https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
>
> No! Cart is an OBJECT there:
>
> "cart":{
> ...
> }
>
> Also contact details:
>
> "contact_details":{
> ...
> }
>
> The "{" indicates the beginning of an OBJECT while "[" starts an ARRAY.
>
> As I said: learn how to read JSON and try to understand how that format
> works!
>
> Also see: <https://www.json.org/json-en.html>

In addition:

To create an OBJECT in PHP use something like this - as a reduced example:

<?php
class CartItem
{ public $url;
public $description;
public $product_code;
public $unit_cost;
public $quantity;
}

class TaxItem
{ public $amount;
public $description;
public $rate;
}

class Cart
{ public $items;
public $subtotal;
public $tax;
};

$cart = new Cart();

$cartItem = new CartItem();
$cartItem->url = "https:\/\/example.com\/examples\/item1.jpg";
$cartItem->description = "One item";
$cartItem->product_code = "one_item";
$cartItem->unit_cost = "100.00";
$cartItem->quantity = "1";
$cart->items[] = $cartItem;

$cartItem = new CartItem();
$cartItem->url = "https:\/\/example.com\/examples\/item2.jpg";
$cartItem->description = "Two item";
$cartItem->product_code = "two_item";
$cartItem->unit_cost = "200.00";
$cartItem->quantity = "1";
$cart->items[] = $cartItem;

$cartItem = new CartItem();
$cartItem->url = "https:\/\/example.com\/examples\/item3.jpg";
$cartItem->description = "Three item";
$cartItem->product_code = "three_item";
$cartItem->unit_cost = "100.00";
$cartItem->quantity = "1";
$cart->items[] = $cartItem;

$cart->subtotal = "400.00";

$taxItem = new TaxItem();
$taxItem->amount = "52.00";
$taxItem->description = "Taxes";
$taxItem->rate = "13.00";
$cart->tax = $taxItem;

echo json_encode($cart, JSON_PRETTY_PRINT);
?>

Result of this as formatted output:

{
"items": [
{
"url": "https:\\\/\\\/example.com\\\/examples\\\/item1.jpg",
"description": "One item",
"product_code": "one_item",
"unit_cost": "100.00",
"quantity": "1"
},
{
"url": "https:\\\/\\\/example.com\\\/examples\\\/item2.jpg",
"description": "Two item",
"product_code": "two_item",
"unit_cost": "200.00",
"quantity": "1"
},
{
"url": "https:\\\/\\\/example.com\\\/examples\\\/item3.jpg",
"description": "Three item",
"product_code": "three_item",
"unit_cost": "100.00",
"quantity": "1"
}
],
"subtotal": "400.00",
"tax": {
"amount": "52.00",
"description": "Taxes",
"rate": "13.00"
}
}

Hopefully you understand the idea now - if you don't want an ARRAY in
the JSON then do not create one! If the specification asks for an OBJECT
then use an OBJECT based on a class with named members.

--
Arno Welzel
https://arnowelzel.de

Re: Stripping a JSON of extra characters in PHP

<trtsrr$19ol$37@gallifrey.nk.ca>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=808&group=comp.lang.php#808

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.nk.ca!.POSTED.doctor.nl2k.ab.ca!not-for-mail
From: doctor@doctor.nl2k.ab.ca (The Doctor)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Tue, 7 Feb 2023 16:05:15 -0000 (UTC)
Organization: NetKnow News
Message-ID: <trtsrr$19ol$37@gallifrey.nk.ca>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <k4d3dvFtd5nU1@mid.individual.net> <trs7m0$2pkv$29@gallifrey.nk.ca> <k4efhpF59f9U1@mid.individual.net>
Injection-Date: Tue, 7 Feb 2023 16:05:15 -0000 (UTC)
Injection-Info: gallifrey.nk.ca; posting-host="doctor.nl2k.ab.ca:204.209.81.1";
logging-data="42773"; mail-complaints-to="usenet@gallifrey.nk.ca"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: doctor@doctor.nl2k.ab.ca (The Doctor)
 by: The Doctor - Tue, 7 Feb 2023 16:05 UTC

In article <k4efhpF59f9U1@mid.individual.net>,
Arno Welzel <usenet@arnowelzel.de> wrote:
>The Doctor, 2023-02-07 01:57:
>
>> In article <k4d3dvFtd5nU1@mid.individual.net>,
>> Arno Welzel <usenet@arnowelzel.de> wrote:
>>> The Doctor, 2023-02-06 16:28:
>>>
>>> [...]
>>>> The cart is being derived from a previous form being passed into PHP!
>>>
>>> [...]
>>>> $arr=array(
>>>> 'store_id' => "store3",
>>>> 'api_token' => "yesguy",
>>>> 'checkout_id' => "chktGLFZQtore3",
>>>> 'txn_total' => $_POST['charge_total'],
>>>> 'environment' => "qa",
>>>> 'action' => "preload",
>>>> 'cart' => array(
>>>> (foreach ($_POST['quantity'] as $key => $value) {
>>>
>>> Well - this will result in an array in the JSON named "cart".
>>>
>>>> $cart['items'][] =array(
>>>
>>> And this will also become an array named "items" inside "cart".
>>>
>>> So if you don't want "cart" to be an array in the JSON, then don't
>>> create it this way.
>>>
>>> Learn how to read JSON and that the "punctuation" are not just
>>> characters but have a specific meaning. In this case you created an
>>> array and the JSON will have an array as well - indicated by "[" and "]".
>>>
>>
>> Again basing this on Moneris prereqs.
>
>What is "Moneris prereqs"?
>
>Your OP was: "How can I carefully strip unnecessary punctuation?" I
>tried to explain to you, where these "punctuation" comes from. But if
>you don't accept the facts, then you have to live with it.
>
>

https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet

>--
>Arno Welzel
>https://arnowelzel.de
>

--
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b
Extremism is for those who love judging, and care nothing for accuracy. -unknown Beware https://mindspring.com

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor