Constructing JSON with children

I am trying to construct my JSON to look like so…with the __children: [ coming right after Qty Shipped: null,

[
    {
        'Job Number': '22983321',
        'LN #': null,
        'Description': null,
        'Qty': null,
        'AS400 Ship Date': null,
        'Date Showed on Report': null,
        'Days to Manufacture': null,
        'Notes': null,
        'Date Shown Completed': null,
        'Actual Ship Date': null,
        'Qty Shipped': null,
        __children: [
            {
                //values here
            },
        ]
    },
]

With my current code what I am getting is this:

{
    "0": {
        "Job Number": "22359501",
        "LN #": null,
        "Description": null,
        "Qty": null,
        "AS400 Ship Date": null,
        "Date Showed on Report": null,
        "Days to Manufacture": null,
        "Notes": null,
        "Date Shown Completed": null,
        "Actual Ship Date": null,
        "Qty Shipped": null
    },
    "_children": [
        {
            //values here
        },
    ]
}

This is my current code:

$checkJob = '';

//output data into spreadsheet view
while($row = $stmt->fetch(PDO::FETCH_BOUND)) {
    if ($checkJob == $job_number) {
        //print "<b>checkJob: " . $checkJob . " | " . "currentJob: " . $job_number . "</b><br>";
        $json['__children'][] = array(
            'LN #' => $line_item,
            'Description' => $description,
            'Qty' => $qty,
            'AS400 Ship Date' => $as400_ship_date,
            'Date Showed on Report' => $date_showed_on_report,
            'Days to Manufacture' => "5",
            'Notes' => $notes,
            'Date Shown Completed' => $date_shown_complete,
            'Actual Ship Date' => $actual_ship_date,
            'Qty Shipped' => $qty_shipped
        );
    }
    else {
        $checkJob = $job_number;
        //print "checkJob: " . $checkJob . " | " . "currentJob: " . $job_number . "<br>";
        $json[] = array(
            'Job Number' => $job_number,
            'LN #' => null,
            'Description' => null,
            'Qty' => null,
            'AS400 Ship Date' => null,
            'Date Showed on Report' => null,
            'Days to Manufacture' => null,
            'Notes' => null,
            'Date Shown Completed' => null,
            'Actual Ship Date' => null,
            'Qty Shipped' => null,
        );
    }
}

I tried changing $json[][] = array( to $json['__children'][] = array( and it’s still not structuring the JSON correctly. I am trying to build the JSON using built in functions as suggested…

        $json[] = array(
            'LN #' => $line_item,
            'Description' => $description,
            'Qty' => $qty,
            'AS400 Ship Date' => $as400_ship_date,
            'Date Showed on Report' => $date_showed_on_report,
            'Days to Manufacture' => "5",
            'Notes' => $notes,
            'Date Shown Completed' => $date_shown_complete,
            'Actual Ship Date' => $actual_ship_date,
            'Qty Shipped' => $qty_shipped,
            '__children' => ['whatever']
        );
Sponsor our Newsletter | Privacy Policy | Terms of Service