Sample code for 30+ languages & platforms
PHP

JSON Hex Encoding

See more JSON Examples

Let's say your JSON contains content that is hex encoded like this: \u05d1\u05d3\u05d9\u05e7

This example shows how to get the decoded string.

Chilkat PHP Downloads

PHP
<?php

use Chilkat2\JsonObject;
use Chilkat2\StringBuilder;

$s = '{ "example": "\u05d1\u05d3\u05d9\u05e7" }';

$json = new JsonObject();

$json->Load($s);

// When getting the member data, it is automatically decoded.
echo 'member data: ', $json->StringOf('example'), "\n";

// Output:
// member data: בדיק

// When getting the full JSON, it remains encoded. This is expected and intentional.
echo 'full JSON: ', $json->Emit(), "\n";

// Output:
// full JSON: {"example":"\u05d1\u05d3\u05d9\u05e7"}

// To get the full JSON without the encoding, you can decode manually.
$sb = new StringBuilder();
$json->EmitSb($sb);
// The hex encoding used by JSON is utf-8.
$sb->Decode('json', 'utf-8');

echo $sb->GetAsString(), "\n";

// Output:
// {"example":"בדיק"}