AnsweredAssumed Answered

JSON -> XML -> JSON : structure preservation

Question asked by Nicolas Afonso Employee on Dec 8, 2015
Latest reply on Dec 16, 2015 by jjurisch

Dear community,

 

I need your experience for helping me to solve my problem !

 

I need, on a JSON flow, depending on consumer of my service, to filter some parts of the JSON (remove / add nodes).

 

The most clean way to achieve this from my point of view is to transform JSON to XML, do some XSLT operations and redo a transformation to JSON.

 

OK but first problem : some JSON structure elements from original message are lost during JSON -> XML transformation :

 

- a node containing an empty array will be stripped during transformation

- a node containing an array with only one entry will not be retransformed into an array after round up transformation, but as a single object

 

{

"test": [{"test2" : "value"}]

}

 

to XML ->

 

<?xml version="1.0" encoding="UTF-8"?>

<root>

    <test>

        <test2>value</test2>

    </test>

</root>

 

-> to JSON

{

"test": {"test2" : "value"}

}

 

Any good practice to preserve original JSON structure ? I do not know JSONML, I am not sure I can use this here.

 

Thank you

Outcomes