2017 © Pedro Peláez
 

library jsonx

JSONx is an IBM standard for representing JSON as XML

image

danharper/jsonx

JSONx is an IBM standard for representing JSON as XML

  • Monday, November 23, 2015
  • by danharper
  • Repository
  • 2 Watchers
  • 5 Stars
  • 1,516 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 65 % Grown

The README.md

JSONx

Latest Stable Version License, (*1)

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., (*2)

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., (*3)

Installation

composer require danharper/jsonx

Usage

$jsonx = new danharper\JSONx\JSONx;

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

/*

<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('

<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., (*4)

Want automatic conversion of your PSR-7 compatible messages? Check out danharper/psr7-jsonx., (*5)

The Versions

23/11 2015

dev-master

9999999-dev

JSONx is an IBM standard for representing JSON as XML

  Sources   Download

MIT

The Development Requires

json xml ibm jsonx

22/11 2015

v0.1.0

0.1.0.0

JSONx is an IBM standard format to represent JSON as XML https://twitter.com/danharper7/status/514822464673951744

  Sources   Download

MIT

The Development Requires