src/Format/JsonFormat.php
public function stringToObject($data, array $options=[])
  {
    $data = trim($data);
    if ( substr($data, 0, 1) !== '{' && substr($data, -1, 1) !== '}' ){
      return Format::getInstance('Yaml')->stringToObject($data, $options);
    }
    
    $decoded = json_decode($data);
    
    if ( $decoded === null ){
      throw new \RuntimeException(sprintf('Error decoding JSON data: %s', json_last_error_msg()));
    }
    
    return (object)$decoded;
  }
public function stringToObject($data, array $options=[])
  {
    $data = trim($data);
    if ( substr($data, 0, 1) !== '{' && substr($data, -1, 1) !== '}' ){
      return Format::getInstance('Yaml')->stringToObject($data, $options);
    }
    
    $decoded = json_decode($data);
    
    if ( $decoded === null ){
      throw new \RuntimeException(sprintf('Error decoding JSON data: %s', json_last_error_msg()));
    }
    
    return (object)$decoded;
  }
public function stringToObject ( $ data , array $ options = [ ] ) { $ data = trim ( $ data ) ; if ( substr ( $ data , 0 , 1 ) !== '{' && substr ( $ data , - 1 , 1 ) !== '}' ) { return Format :: getInstance ( 'Yaml' ) -> stringToObject ( $ data , $ options ) ; } $ decoded = json_decode ( $ data ) ; if ( $ decoded === null ) { throw new \ RuntimeException ( sprintf ( 'Error decoding JSON data: %s' , json_last_error_msg ( ) ) ) ; } return ( object ) $ decoded ; }
Parse a JSON formatted string and convert it into an object

If not JSON tries YML.

@param   string  $data     JSON formatted string to convert
@param   array   $options  Options used by the formatter
@return   object   Data object
Parse a JSON formatted string and convert it into an object