从JSON(PHP)中删除项目

I reviewed a lot of post to delete an item from JSON with PHP but somehow the 'unset' function is not working anywhere in my code. How can I delete 'SPEC_Info' from my JSON file with the code below I created to merge different JSON files (URLs)?

$sets = array();
foreach ($urls as $url)
{
    $json = file_get_contents($url);
    $data = json_decode($json);
    $json = substr($json, 1, -1);
    $sets = array_merge($sets, $data);
}

$new = json_encode($sets, JSON_PRETTY_PRINT);
echo '<pre>';
echo $new;

$fp = fopen('dsales_watchjewel_combined_en.json', 'w');
fwrite($fp, $new);
fclose($fp);
$sets = array();
foreach ($urls as $url)
{
    $json = file_get_contents($url);
    $decoded = json_decode($json, true);
    oreach ($decoded as $key => $innerObject) { //based on the fact that your JSON contains multiple inner objects.
        if(isset($innerObject['SPEC_Info'])) {
            unset($decoded[$key]['SPEC_Info']);
        }
    }
    $sets[] = $decoded;
}
$new = json_encode($sets, JSON_PRETTY_PRINT);
echo '<pre>';
echo $new;

$fp = fopen('combined.json', 'w');
fwrite($fp, $new);
close($fp);

JSON is text. Also is the content of $json.

Evaluating the expression $json['SPEC_Info'] triggers a warning (you cannot use string offsets in strings), converts 'SPEC_Info' to a number (0) and accesses the first character of $json.

unset() cannot be used with $json['SPEC_Info']. It doesn't make any sense.

JSON is a text representation of some data structure. In order to use it you have to decode the JSON back into the original data structure. PHP provides the json_decode() for this purpose. Pass TRUE as its second argument to ask it to return arrays, not objects (they are easier to manipulate).

This answers handles only the "why unset() doesn't work" part of the question. See this answer provided by @Auris to find out how to handle the JSON properly.

Here is my final code with combining my JSON files + removing multiple items.

$urls = array
( 'URL'
, 'URL'
);

$sets = array();
foreach ($urls as $url)
{
    $json = file_get_contents($url);
    $data = json_decode($json, true);
    foreach ($data as $key => $innerObject) { //based on the fact that your JSON contains multiple inner objects.
        if (isset(
            $innerObject['SPEC_Bullet point 1'],
            $innerObject['SPEC_Bullet point 2'],
            $innerObject['SPEC_Bullet point 3'],
            $innerObject['SPEC_Bullet point 4'],
            $innerObject['SPEC_Bullet point 5'],
            $innerObject['SPEC_Extra info'],
            $innerObject['SPEC_Keywords'],
            $innerObject['SPEC_Featured'],
            $innerObject['SPEC_Bullet point 1 TEXT'],
            $innerObject['SPEC_Bullet point 2 LIST'],
            $innerObject['SPEC_Bullet Point 1'],
            $innerObject['SPEC_Bullet point 2 TEXT'],
            $innerObject['SPEC_Bullet Point 1 TEXT'],
            $innerObject['SPEC_Bullet Point 2'],
            $innerObject['SPEC_Bullet point 3 LIST'],
            $innerObject['SPEC_Bullet Point 2 TEXT'],
            $innerObject['SPEC_Bullet point 3 TEXT'],
            $innerObject['SPEC_Bullet point 4 LIST'],
            $innerObject['SPEC_Bullet point 4 TEXT'],
            $innerObject['SPEC_Bullet Point 3'],
            $innerObject['SPEC_Bullet Point 3 TEXT'],
            $innerObject['SPEC_Bullet point 5 LIST'],
            $innerObject['SPEC_Bullet point 5 TEXT'],
            $innerObject['SPEC_Bullet Point 4 TEXT'],
            $innerObject['SPEC_Bullet Point 5'],
            $innerObject['SPEC_Bullet Point 5 TEXT'],
            $innerObject['SPEC_Bullet point 1 LIST']
        )) {
            unset(
                $data[$key]['SPEC_Bullet point 1'],
                $data[$key]['SPEC_Bullet point 2'],
                $data[$key]['SPEC_Bullet point 3'],
                $data[$key]['SPEC_Bullet point 4'],
                $data[$key]['SPEC_Bullet point 5'],
                $data[$key]['SPEC_Extra info'],
                $data[$key]['SPEC_Keywords'],
                $data[$key]['SPEC_Featured'],
                $data[$key]['SPEC_Bullet point 1 TEXT'],
                $data[$key]['SPEC_Bullet point 2 LIST'],
                $data[$key]['SPEC_Bullet Point 1'],
                $data[$key]['SPEC_Bullet point 2 TEXT'],
                $data[$key]['SPEC_Bullet Point 1 TEXT'],
                $data[$key]['SPEC_Bullet Point 2'],
                $data[$key]['SPEC_Bullet point 3 LIST'],
                $data[$key]['SPEC_Bullet Point 2 TEXT'],
                $data[$key]['SPEC_Bullet point 3 TEXT'],
                $data[$key]['SPEC_Bullet point 4 LIST'],
                $data[$key]['SPEC_Bullet point 4 TEXT'],
                $data[$key]['SPEC_Bullet Point 3'],
                $data[$key]['SPEC_Bullet Point 3 TEXT'],
                $data[$key]['SPEC_Bullet point 5 LIST'],
                $data[$key]['SPEC_Bullet point 5 TEXT'],
                $data[$key]['SPEC_Bullet Point 4 TEXT'],
                $data[$key]['SPEC_Bullet Point 5'],
                $data[$key]['SPEC_Bullet Point 5 TEXT'],
                $data[$key]['SPEC_Bullet point 1 LIST']
            );
        }
    }
    $json = substr($json, 1, -1);
    $sets = array_merge($sets, $data);
}

$new = json_encode($sets, JSON_PRETTY_PRINT);
echo '<pre>';
echo $new;

$fp = fopen('combined.json', 'w');
fwrite($fp, $new);
fclose($fp);