Layer7 API Management

  • 1.  Not able to convert Json to xml with json having prefix?

    Posted Dec 18, 2017 07:59 AM

    I am not able to convert below json into Xml and getting bound error(Standard transformation) and Error in XML generated (using JsonML transformation).

    I am using Json Transformation assertion to do so.

     

    Can you please help me out to convert it? I have tried adding prefix in root element "info:SessionEvent" but it didn't help.

     

    {
    "info:SessionEvent": {
    "-xmlns:info": "urn:Namespaces.xyz.Com:Nrm:Nro:Session:v0001",
    "info:SessionId": "128987732",
    "info:SessionDetails": {
    "info:SessionCoreDetails": {
    "info:SessionID": "null",
    "info:SessionName": "1027593-Test Activity template 1",
    "info:SessionType": "null"
    },
    "info:ParentReferences": {
    "info:ProjectRecordName": "1000003 - Dev",
    "info:WorkPlanRecordName": "1000934-AJ-Congo updated for 1076-AJ",
    "info:RecordName": "1027593-Test Activity template 1",
    "info:Site": "Congo updated for 1076",
    "info:Customer": "xyz"
    },
    "info:AssigneeReference": {
    "info:AssigneeFullName": "Xyz user",
    "info:AssigneePhone": "null",
    "info:AssigneeEmail": "test@test.com"
    }
    }
    }
    }



  • 2.  Re: Not able to convert Json to xml with json having prefix?
    Best Answer

    Broadcom Employee
    Posted Dec 18, 2017 09:24 AM

    Hi Apurva,

     

    The problem with this is that the JSON string that's being provided does not follow well-known encoding for XML. XML

    distinguishes between attributes and subtags, but JSON has no such distinction.

     

    Because of this problem, different ways have come up to shoehorn that distinction into JSON, and none of them are intuitive or straightforward.


    i.e: http://lists.xml.org/archives/xml-dev/201506/msg00024.html

     

    "Be aware that more complex XML structures (such as namespace, attributes) may not be transformed correctly."

    https://docops.ca.com/ca-api-gateway/9-2/en/policy-assertions/assertion-palette/message-validation-transformation-assertions/apply-json-transformation-assertion/

     

    The same issue is seen on 3rd party websites: Free Online JSON to XML Converter - FreeFormatter.com 

     

    Regards,
    Joe



  • 3.  RE: Re: Not able to convert Json to xml with json having prefix?

    Posted Apr 14, 2021 06:04 PM
    Hi Apoorvkapil,

    i checked your JSON and it converts perfectly to XML with this tool convert json to xml

    <?xml version="1.0"?>
    <root>
    	<SessionEvent>
    		<info>urn:Namespaces.xyz.Com:Nrm:Nro:Session:v0001</info>
    		<SessionId>128987732</SessionId>
    		<SessionDetails>
    			<SessionCoreDetails>
    				<SessionID>null</SessionID>
    				<SessionName>1027593-Test Activity template 1</SessionName>
    				<SessionType>null</SessionType>
    			</SessionCoreDetails>
    			<ParentReferences>
    				<ProjectRecordName>1000003 - Dev</ProjectRecordName>
    				<WorkPlanRecordName>1000934-AJ-Congo updated for 1076-AJ</WorkPlanRecordName>
    				<RecordName>1027593-Test Activity template 1</RecordName>
    				<Site>Congo updated for 1076</Site>
    				<Customer>xyz</Customer>
    			</ParentReferences>
    			<AssigneeReference>
    				<AssigneeFullName>Xyz user</AssigneeFullName>
    				<AssigneePhone>null</AssigneePhone>
    				<AssigneeEmail>test@test.com</AssigneeEmail>
    			</AssigneeReference>
    		</SessionDetails>
    	</SessionEvent>
    </root>
    ​