Re: Stripping a JSON of extra characters in PHP

"J.O. Aho" <[email protected]> Mon, 6 Feb 2023 08:14:28 +0100
Newsgroups comp.lang.php
Message-ID <[email protected]>
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