Syntax

PHP Encode and Decode JSON Syntax

In PHP, encode and decode json: converts between arrays and JSON — json_encode($data); json_decode($json, true);

Quick Answer

Syntax
json_encode($data); json_decode($json, true);
PHPSyntax

Encode and Decode JSON

Code example
json_encode($data); json_decode($json, true);

Converts between arrays and JSON.

Learn More

How to encode and decode json in PHP

  1. Open your PHP file or editor.
  2. Copy the example, then replace its sample names and values for your code.

PHP Encode and Decode JSON Syntax

Use json_encode($data); json_decode($json, true);.

Related Syntax References

Frequently asked questions

What is the PHP syntax for encode and decode json?

Use this pattern: json_encode($data); json_decode($json, true);

Can I copy this PHP code example?

Yes. Use Copy code and adapt the example to your program.

Is this PHP syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify