[Solved] JSON inside XML | 9to5Answer

I want to know about standard and best practice in :

Case Scenario :

If a xml standard exist by “XYZ SPECIFICATION” (ex : BPMN Specification) like :

<home>
<person name="ZEN" />
<person name="PAUL" />
<animal name="DOG" />
<animal name="CAT" />
</home>

and “XYZ SPECIFICATION” also provide extension element to define your own tag like :

   <home>
    <person name="ZEN" />
    <person name="PAUL" />
    <animal name="DOG" />
    <animal name="CAT" />
    <extension>
    <instrument-list>
    <type name="acoustic">
      <instrument name="GUITAR" />
      <instrument name="VIOLIN"  />
    </type>
    <type name="electronic">
      <instrument name="GUITAR" />
      <instrument name="VIOLIN"/>
    </type>
    </instrument-list>
    </extension>
    </home>

Tag defined by standard are used by other client parser , they don’t need to parse extension tag so i was thinking that it would be better to compress extension element using json (because json takes less space in compare to xml) :

  <home>
    <person name="ZEN" />
    <person name="PAUL" />
    <animal name="DOG" />
    <animal name="CAT" />
    <extension>
    <instrument-list>{"type":[{"name":"acoustic","instrument":[{"name":"GUITAR"},{"name":"VIOLIN"}]},{"name":"electronic","instrument":[{"name":"GUITAR"},{"name":"VIOLIN"}]}]}</instrument-list>
    </extension>
    </home>

or

<home>
    <person name="ZEN" />
    <person name="PAUL" />
    <animal name="DOG" />
    <animal name="CAT" />
    <extension>
    <instrument-list><![CDATA[ {"type":[{"name":"acoustic","instrument":[{"name":"GUITAR"},{"name":"VIOLIN"}]},{"name":"electronic","instrument":[{"name":"GUITAR"},{"name":"VIOLIN"}]}]} ]]></instrument-list>
    </extension>
    </home>

Is it violates standard and best practices ?

Read more here: Source link