Predefined Constants

The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

The following constants indicate the type of error returned by json_last_error() or stored as the code of a JsonException.

JSON_ERROR_NONE (int)
No error has occurred.
JSON_ERROR_DEPTH (int)
The maximum stack depth has been exceeded.
JSON_ERROR_STATE_MISMATCH (int)
Occurs with underflow or with the modes mismatch.
JSON_ERROR_CTRL_CHAR (int)
Control character error, possibly incorrectly encoded.
JSON_ERROR_SYNTAX (int)
Syntax error.
JSON_ERROR_UTF8 (int)
Malformed UTF-8 characters, possibly incorrectly encoded.
JSON_ERROR_RECURSION (int)
The object or array passed to json_encode() include recursive references and cannot be encoded. If the JSON_PARTIAL_OUTPUT_ON_ERROR option was given, null will be encoded in the place of the recursive reference.
JSON_ERROR_INF_OR_NAN (int)
The value passed to json_encode() includes either NAN or INF. If the JSON_PARTIAL_OUTPUT_ON_ERROR option was given, 0 will be encoded in the place of these special numbers.
JSON_ERROR_UNSUPPORTED_TYPE (int)
A value of an unsupported type was given to json_encode(), such as a resource. If the JSON_PARTIAL_OUTPUT_ON_ERROR option was given, null will be encoded in the place of the unsupported value.
JSON_ERROR_INVALID_PROPERTY_NAME (int)
A key starting with \u0000 character was in the string passed to json_decode() when decoding a JSON object into a PHP object.
JSON_ERROR_UTF16 (int)
Single unpaired UTF-16 surrogate in unicode escape contained in the JSON string passed to json_decode().

The following constants can be combined to form options for json_decode().

JSON_BIGINT_AS_STRING (int)
Decodes large integers as their original string value.
JSON_OBJECT_AS_ARRAY (int)
Decodes JSON objects as PHP array. This option can be added automatically by calling json_decode() with the second parameter equal to true.

The following constants can be combined to form options for json_encode().

JSON_HEX_TAG (int)
All < and > are converted to \u003C and \u003E.
JSON_HEX_AMP (int)
All & are converted to \u0026.
JSON_HEX_APOS (int)
All ' are converted to \u0027.
JSON_HEX_QUOT (int)
All " are converted to \u0022.
JSON_FORCE_OBJECT (int)
Outputs an object rather than an array when a non-associative array is used. Especially useful when the recipient of the output is expecting an object and the array is empty.
JSON_NUMERIC_CHECK (int)
Encodes numeric strings as numbers.
JSON_PRETTY_PRINT (int)
Use whitespace in returned data to format it.
JSON_UNESCAPED_SLASHES (int)
Don't escape /.
JSON_UNESCAPED_UNICODE (int)
Encode multibyte Unicode characters literally (default is to escape as \uXXXX).
JSON_PARTIAL_OUTPUT_ON_ERROR (int)
Substitute some unencodable values instead of failing.
JSON_PRESERVE_ZERO_FRACTION (int)
Ensures that float values are always encoded as a float value.
JSON_UNESCAPED_LINE_TERMINATORS (int)
The line terminators are kept unescaped when JSON_UNESCAPED_UNICODE is supplied. It uses the same behaviour as it was before PHP 7.1 without this constant. Available as of PHP 7.1.0.

The following constants can be combined to form options for json_decode() and json_encode().

JSON_INVALID_UTF8_IGNORE (int)
Ignore invalid UTF-8 characters. Available as of PHP 7.2.0.
JSON_INVALID_UTF8_SUBSTITUTE (int)
Convert invalid UTF-8 characters to \0xfffd (Unicode Character 'REPLACEMENT CHARACTER') Available as of PHP 7.2.0.
JSON_THROW_ON_ERROR (int)
Throws JsonException if an error occurs instead of setting the global error state that is retrieved with json_last_error() and json_last_error_msg(). JSON_PARTIAL_OUTPUT_ON_ERROR takes precedence over JSON_THROW_ON_ERROR. Available as of PHP 7.3.0.

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

PHP cURL Tutorial: Using cURL to Make HTTP Requests

cURL is a powerful PHP extension that allows you to communicate with different servers using various protocols, including HTTP, HTTPS, FTP, and more. ...

TheMax

Autor : TheMax
Category: PHP-Tutorials

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial