xml to json period in the key

k_prathip
Participant III

Hi Team,

I am trying to convert an XML to JSON and one of the json key has a perid('.') like first.name

I am not able to get the content of that key as I am getting javascript error.

Below is the sample JSON:

{ "first": { "sec.one":{ "third":"fourth" } } }

If I try first.sec.one it trying to get a key with name sec and insode that searching for another key with name as one.

0 1 238
1 REPLY 1

@Prathip ,

I don't it has anything to do with Apigee. It's the javascript& the way you are trying to access same.

I got it working in sample proxy,

var jsonPayload = JSON.parse(context.getVariable("jsonPayload"));
print(jsonPayload.root.first["sec.one"].third);

See attached proxy & sample curl call,

no-target-8-rev1-2017-11-20.zip

CURL,

curl -X POST \
  http://apigee4mv4d-test.apigee.net/no-target-8 \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/xml' \
  -H 'postman-token: ca2376d2-6d24-11db-8fd6-015d4582a46b' \
  -d '<?xml version="1.0" encoding="UTF-8"?>
<root>
   <first>
      <sec.one>
         <third>fourth</third>
      </sec.one>
   </first>
</root>'

5961-apigee4mv4d-apigee-and-apigee-partner-te-edgepartn.png