v0.2.2 2016-07-30 18:22 UTC

This package is not auto-updated.

Last update: 2023-05-27 12:03:25 UTC


Packagist Packagist

A library to read and write to the Universal Binary JSON (Draft 9) format using PHP

Install using composer

Using command line:

composer require fandogh/php-ubjson

Or add this to your composer.json file:

"require": {
  "fandogh/php-ubjson": "^0.2.2",


PLEASE NOTE THAT ENCODED RESULT IS A BINARY STRING and some charachters are non printable!!

// Don't forget to require autoload.php with correct path
require './vendor/autoload.php';

// Test data
$payload = ['hello'=>123];

// Encode using UBJSON
$encoded = \UBJSON::encode($payload);

# Incorrect! 
echo($encoded); // {SU�helloU{}

# Correct!
echo(bin2hex($encoded)); // "7b53550568656c6c6f557b7d"

// Test decoding
$decoded = \UBJSON::decode($encoded);

var_dump($decoded); // array(1) { ["hello"]=> int(123) }


This code is distributed under BSD license.