Index: src/wp-includes/functions.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/functions.php	(date 1471700875000)
+++ src/wp-includes/functions.php	(date 1471701027000)
@@ -2871,6 +2871,9 @@
  * @return string|false The JSON encoded string, or false if it cannot be encoded.
  */
 function wp_json_encode( $data, $options = 0, $depth = 512 ) {
+	// Prepare the data for JSON serialization.
+    $data = _wp_json_prepare_data( $data );
+
 	/*
 	 * json_encode() has had extra params added over the years.
 	 * $options was added in 5.3, and $depth in 5.5.
@@ -2884,8 +2887,6 @@
 		$args = array( $data );
 	}
 
-	// Prepare the data for JSON serialization.
-	$args[0] = _wp_json_prepare_data( $data );
 
 	$json = @call_user_func_array( 'json_encode', $args );
 
@@ -2897,7 +2898,7 @@
 	}
 
 	try {
-		$args[0] = _wp_json_sanity_check( $data, $depth );
+		$args[0] = _wp_json_sanity_check( $args[0], $depth );
 	} catch ( Exception $e ) {
 		return false;
 	}
