final public function asJson(
        $options = 0,
        $depth = 512)
    {
        if (!is_int($options) || !is_int($depth)) {
            throw new LazyJsonMapperException('Invalid non-integer function argument.');
        }

        // Create a fully-validated, fully-converted final object-tree.
        // NOTE: See `jsonSerialize()` for details about why we MUST do this.
        $objectData = $this->exportObjectDataCopy('stdClass'); // Throws.

        // Gracefully handle JSON encoding and validation.
        $jsonString = @json_encode($objectData, $options, $depth);
        if ($jsonString === false) {
            throw new LazyJsonMapperException(sprintf(
                'Failed to encode JSON string (error %d: "%s").',
                json_last_error(), json_last_error_msg()
            ));
        }

        return $jsonString;
    }
final public function asJson(
        $options = 0,
        $depth = 512)
    {
        if (!is_int($options) || !is_int($depth)) {
            throw new LazyJsonMapperException('Invalid non-integer function argument.');
        }

        // Create a fully-validated, fully-converted final object-tree.
        // NOTE: See `jsonSerialize()` for details about why we MUST do this.
        $objectData = $this->exportObjectDataCopy('stdClass'); // Throws.

        // Gracefully handle JSON encoding and validation.
        $jsonString = @json_encode($objectData, $options, $depth);
        if ($jsonString === false) {
            throw new LazyJsonMapperException(sprintf(
                'Failed to encode JSON string (error %d: "%s").',
                json_last_error(), json_last_error_msg()
            ));
        }

        return $jsonString;
    }
final public function asJson ( $ options = 0 , $ depth = 512 ) { if ( ! is_int ( $ options ) || ! is_int ( $ depth ) ) { throw new LazyJsonMapperException ( 'Invalid non-integer function argument.' ) ; } // Create a fully-validated, fully-converted final object-tree. // NOTE: See `jsonSerialize()` for details about why we MUST do this. $ objectData = $ this -> exportObjectDataCopy ( 'stdClass' ) ; // Throws. // Gracefully handle JSON encoding and validation. $ jsonString = @ json_encode ( $ objectData , $ options , $ depth ) ; if ( $ jsonString === false ) { throw new LazyJsonMapperException ( sprintf ( 'Failed to encode JSON string (error %d: "%s").' , json_last_error ( ) , json_last_error_msg ( ) ) ) ; } return $ jsonString ; }
Get a processed representation of this object instance's data as JSON.

This helper gives you a JSON string representation of the object's
internal data, and provides the necessary interface to fully control
the JSON encoding process.

It handles all steps for you and wraps everything in nice exceptions,
and will even clearly explain any `json_encode()` errors in plain English
(although the default settings will never cause any encoding failures).
And most importantly, this function also guarantees that your data is
ALWAYS properly encoded as a valid JSON object `{}` (rather than risking
getting the result as a JSON array such as `[]` or `["a","b","c"]`).
We accept all of the same parameters as the `json_encode()` function!

Note that we only encode properties that exist in the actual internal
data. Anything that merely exists in the class property map is omitted.

`WARNING:` It is worth saving the output of this function if you intend
to use the result multiple times, since each call to this function will
internally use `exportObjectDataCopy()`, which performs quite intensive
work to recursively validate and convert values while creating the final
representation of the object's internal JSON data. Please read the
description of `exportObjectDataCopy()` for more information.

@param int $options Bitmask to control `json_encode()` behavior.
@param int $depth   Maximum JSON depth. Encoding fails if set too low.
Can almost always safely be left at `512` (default).

@throws LazyJsonMapperException If there are any conversion problems.

@return string

@see http://php.net/json_encode
@see LazyJsonMapper::exportObjectDataCopy()
@see LazyJsonMapper::asStdClass()
@see LazyJsonMapper::asArray()
@see LazyJsonMapper::printJson()
@see LazyJsonMapper::jsonSerialize()        The native json_encode()
serializer instead.
Get a processed representation of this object instance s data as JSON .