I need to create a json response to look like Stripe API response using PHP. This is the structure I want to get:
{ "body": "{\n \"error\": \"Please enter a valid secret key\",\n}\n", }
This is the code I have so far:
first I create the array:
class Error {
public $errors = array(
'body' => array( 'error' => false ),
);
if ($this->errors['body']['error'] === false) {
$this->errors['body']['error'] = 'Please enter a valid secret key'
}
$resp = json_encode( $this->errors )
echo wp_send_json( $resp );
}
but the result I get is: json_encode result:
{"body":{"error":"Please enter a valid secret key"}}
echo wp_send_json( $resp ) result:
res = "{\"body\":{\"error\":\"Please enter a valid secret key\"}}"
I don't want the body to be encoded. What am I missing?
json_encodetwice: first time for$this->errors['body']and then for something likearray('body' => $resp). For ex., sandbox.onlinephpfunctions.com/code/…