Unable to enocde the result of wc_get_products

Try:

$products_posts_arr = (array) $products_posts;
echo json_encode( $products_posts_arr );

OR

function object_to_array($data) {
    if (is_array($data) || is_object($data)) {
        $result = array();
        foreach ($data as $key => $value) {
            $result[$key] = object_to_array($value);
        }
        return $result;
    }
    return $data;
}

$products_posts_arr = object_to_array( $products_posts );
echo json_encode( $products_posts_arr );

Encode array not object, wc_get_products will return object.