Tôi đang cố gắng tạo một đối tượng JSON từ một mảng PHP. Mảng có dạng như sau:
$post_data = array('item_type_id' => $item_type,
    'string_key' => $string_key,
    'string_value' => $string_value,
    'string_extra' => $string_extra,
    'is_public' => $public,
    'is_public_for_contacts' => $public_contacts);
Mã để mã hóa JSON trông như sau:
$post_data = json_encode($post_data);
Cuối cùng thì tệp JSON phải trông như thế này:
{
    "item": {
        "is_public_for_contacts": false,
        "string_extra": "100000583627394",
        "string_value": "value",
        "string_key": "key",
        "is_public": true,
        "item_type_id": 4,
        "numeric_extra": 0
    }
} 
Làm cách nào để đóng gói mã JSON đã tạo trong "item": {JSON CODE HERE}.
JSON_FORCE_OBJECTvàojson_encode($arr, JSON_FORCE_OBJECT)