arabic letters appears as symbols in json

Hello to all,

I want to ask processing json response.

why when I assigned backend response to JSON variable, Arabic characters appears as symbols - set of question marks - ?

I need to customize it before it displayed to the end user.

The backend response:

{
   "totalSearchResults":"1",
   "Info":[
      {
         "ID":"123456789",
         "FirstName":"خالد",
         "FatherName":"فيصل",
         "FamilyName":"الشهري",
         "Address":"حي القادسية"
      }
   ]
}

I want the modified response to be like this:

{   
  "code":200,
  "name":"Successful Response",
  "data":[
   {
     "totalSearchResults":"1",
     "Info":[
      { 
         "ID":"123456789",
         "FirstName":"خالد",
         "FatherName":"فيصل",
         "FamilyName":"الشهري",
         "Address":"حي القادسية"
      }
    ]
   }
  ]
}

But in my attempts, the response appears like this: (notice the Arabic letters are not correct)

{   
  "code":200,
  "name":"Successful Response",
  "data":[
   {
     "totalSearchResults":"1",
     "Info":[
      { 
         "ID":"123456789",
         "FirstName":"ط®ط§ظ„ط¯",
         "FatherName":"ط¹ط¨ط¯ط§ظ„ظ„ظ‡",
         "FamilyName":"ط§ظ„ط´ظ‡ط±ظٹ",
         "Address":"ط­ظٹ ط§ظ„ظ‚ط§ط¯ط³ظٹط©"
      }
    ]
   }
  ]
}

Can anyone help?

thank you.

0 9 3,496
9 REPLIES 9

Can you please show some code and configuration?

I assigned backend response to JSON variable,

How did you do that? using which policy or mechanism? Help us out here.

this is what I did

<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-1">
<DisplayName>Assign Message-1</DisplayName>
<Properties/>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>

<Set>
   <Payload contentType="application/json; charset=utf-8">
     //I add here some JSON 
     {message.content}
   </Payload>
</Set>
</AssignMessage>

You should be able to do that in the JS policy without any issue.
as Dino asked, please share how you are assigning the response to JSON variable.

@Chawki MATTA @Dino-at-Google ♦♦

Thank you for your reply,

For using JS policy, it trippled to deal with because I need to add some JSON and it has alot of ""

I used assign message policy in target response like that:

<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-1">
<DisplayName>Assign Message-1</DisplayName>
<Properties/>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>

<Set>
   <Payload contentType="application/json; charset=utf-8">
     //I add here some JSON 
     {message.content}
   </Payload>
</Set>
</AssignMessage>

what do you mean by //I add here some JSON ? are you trying to add new params ?
elaborate more (can you share the response you are getting from the backend and how its showing in the assign message ?)
NB: if you want to change the parameter value this is not how you can do it.

@Chawki MATTA

The backend response:

{
   "totalSearchResults":"1",
   "Info":[
      {
         "ID":"123456789",
         "FirstName":"خالد",
         "FatherName":"فيصل",
         "FamilyName":"الشهري",
         "Address":"حي القادسية"
      }
   ]
}

I want it to be like that:

{   
  "code":200,
  "name":"Successful Response",
  "data":[
   {
     "totalSearchResults":"1",
     "Info":[
      { 
         "ID":"123456789",
         "FirstName":"خالد",
         "FatherName":"فيصل",
         "FamilyName":"الشهري",
         "Address":"حي القادسية"
      }
    ]
   }
  ]
}

The reponse apears like that: (notice arabic letters)

{   
  "code":200,
  "name":"Successful Response",
  "data":[
   {
     "totalSearchResults":"1",
     "Info":[
      { 
         "ID":"123456789",
         "FirstName":"ط®ط§ظ„ط¯",
         "FatherName":"ط¹ط¨ط¯ط§ظ„ظ„ظ‡",
         "FamilyName":"ط§ظ„ط´ظ‡ط±ظٹ",
         "Address":"ط­ظٹ ط§ظ„ظ‚ط§ط¯ط³ظٹط©"
      }
    ]
   }
  ]
}

There are lots of things to check. It could be that if you are running this from a terminal or command-line prompt, the terminal does not have UTF-8 enabled. if you are running it from a program, It could be that the program has not been coded to handle Unicode correctly.

It also could be that somehow the apigee configuration is incorrect.

It works for me if I add the XML decl at the top of the AssignMessage policy.

Like this:

<?xml version="1.0" encoding="utf-8"?>
<AssignMessage name="AM-AugmentResponse">
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
  <Set>
    <Payload contentType="application/json; charset=utf-8">{
  "code":200,
  "name":"Successful Response",
  "data":[
    {message.content}
  ]
}
</Payload>
  </Set>
</AssignMessage>


What I see in my terminal:

HTTP/1.1 200 OK
Date: Mon, 16 Mar 2020 17:51:26 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 310
Connection: keep-alive


{
  "code":200,
  "name":"Successful Response",
  "data":[
    {
   "totalSearchResults":"1",
   "Info":[
      {
         "ID":"123456789",
         "FirstName":"خالد",
         "FatherName":"فيصل",
         "FamilyName":"الشهري",
         "Address":"حي القادسية"
      }
   ]
}
  ]
}

Working example attached.

json-unicode-example.zip

Not applicable

@Zarah, as Dino said, try adding

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

to your Assignmessage policy beginning and try whether it works as expected.

Not applicable

Can you please show some code and configuration?