json_decode

The WordPress Core json decode function.

Description

(object|array) json_decode( (string) $string, (bool) $assoc_array = false ); 

Returns (object|array)

Parameters (2)

0. $string (string)
The string.
1. $assoc_array — Optional. (bool) => false
The assoc array.

Usage

  1. if ( !function_exists( 'json_decode' ) ) { 
  2. require_once ABSPATH . WPINC . '/compat.php'; 
  3.  
  4. // The string. 
  5. $string = ''; 
  6.  
  7. // The assoc array. 
  8. $assoc_array = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = json_decode($string, $assoc_array); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/compat.php  
  1. function json_decode( $string, $assoc_array = false ) { 
  2. global $wp_json; 
  3.  
  4. if ( ! ($wp_json instanceof Services_JSON ) ) { 
  5. require_once( ABSPATH . WPINC . '/class-json.php' ); 
  6. $wp_json = new Services_JSON(); 
  7.  
  8. $res = $wp_json->decode( $string ); 
  9. if ( $assoc_array ) 
  10. $res = _json_decode_object_helper( $res ); 
  11. return $res;