Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 

JSONx

Latest Stable Version License

A library implementing IBM's standard format for representing JSON as XML. Provides support for both reading & writing of JSONx. The spec draft for JSONx can be found here.

WHY?! That was my initial reaction, too. However it's very useful when you're trying to integrate one system which speaks JSON with another which speaks XML, without having to make potentially large changes.

Installation

composer require danharper/jsonx

Usage

$jsonx = new danharper\JSONx\JSONx;

$jsonx->toJSONx([
  'foo' => [ 'bar', true, 2, 3.14, null, [], (object) [] ]
]);

/*
<?xml version="1.0" encoding="UTF-8"?>
<json:object xmlns:json="http://www.ibm.com/xmlns/prod/2009/jsonx" xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <json:array name="foo">
    <json:string>bar</json:string>
    <json:boolean>true</json:boolean>
    <json:number>2</json:number>
    <json:number>3.14</json:number>
    <json:null/>
    <json:array/>
    <json:object/>
  </json:array>
</json:object>
*/

$jsonx->fromJSONx('
<?xml version="1.0" encoding="UTF-8"?>
<json:object xmlns:json="http://www.ibm.com/xmlns/prod/2009/jsonx" xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <json:array name="foo">
    <json:string>bar</json:string>
    <json:boolean>true</json:boolean>
    <json:number>2</json:number>
    <json:number>3.14</json:number>
    <json:null/>
    <json:array/>
    <json:object/>
  </json:array>
</json:object>
');

/*
object(stdClass)#180 (1) {
  ["foo"]=> array(7) {
    [0]=> string(3) "bar"
    [1]=> bool(true)
    [2]=> int(2)
    [3]=> float(3.14)
    [4]=> NULL
    [5]=> array(0) {
    }
    [6]=> object(stdClass)#173 (0) {
    }
  }
}
*/

Integrations

Want to add full XML support to your JSON-speaking Laravel API with just one middleware? Check out danharper/laravel-jsonx.

Want automatic conversion of your PSR-7 compatible messages? Check out danharper/psr7-jsonx.

About

JSONx is an IBM standard for representing JSON as XML

Resources

License

Packages

No packages published

Languages