Is there a way to run the regex that I have above, only the values?
You are much better off avoiding post-processing the string.
I used to find that when PHP converts array data to JSON, it turns all numeric values ββinto strings, as indicated by double quotes. So, for example, "id": 1 will become "id": "1".
The answer here is to make sure that the numerical values ββare indeed numbers. If you see strings with numbers in them where you expect a number, this is because the value in the PHP object / array is not a number. This is what you need to fix.
For example, this code:
<?php header('Content-Type: application/json'); $x = array( "number" => 1, "string" => "2" ); echo json_encode($x); ?>
... quite correctly produces this conclusion:
{"number":1,"string":"2"}
Notice how the value that is really a number in PHP code is output as a number in JSON.
Therefore, instead of post-processing the string, the response should correct the data that you load in json_encode .
Responding to your comment below:
I understand that I could specifically assign row names to the keys, but the array in question is generated automatically with a while loop that stores the number of additions, and these numbers are used in the counting operations, so I don't think this will work in my case.
It does not matter. For example, this code:
<?php header('Content-Type: application/json'); $x = array(); for ($n = 1; $n < 5; ++$n) { $x["entry" . $n] = $n; } echo json_encode($x); ?>
produces this conclusion:
{"entry1":1,"entry2":2,"entry3":3,"entry4":4}
Note again that numbers are numbers at the input, and therefore numbers at the output.
Also note that PHP correctly processes it if the keys of the object are numbers:
<?php header('Content-Type: application/json'); $x = array(); $x["foo"] = "bar"; for ($n = 1; $n < 5; ++$n) { $x[$n] = $n * 2; } echo json_encode($x); ?>
produces
{"foo":"bar","1":2,"2":4,"3":6,"4":8}