# Pm.response.text() can't work properly with chinese

**URL:** <https://community.postman.com/t/pm-response-text-cant-work-properly-with-chinese/61473>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [May 25, 2024, 10:50am UTC](https://community.postman.com/t/pm-response-text-cant-work-properly-with-chinese/61473 "2024-05-25T10:50:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![wodefan](https://avatars.discourse-cdn.com/v4/letter/w/aeb1de/32.png) [@wodefan](https://community.postman.com/u/wodefan)\
**Post date:** [May 25, 2024, 10:50am UTC](https://community.postman.com/t/pm-response-text-cant-work-properly-with-chinese/61473/1 "2024-05-25T10:50:33Z")

</div>

```auto
pm.test("Body matches string", function () {
    pm.expect(pm.response.text()).to.include("健康");
});

```

When I use the code above to test weather the response contains the chinese word “健康”，the test fails(The response actually contains the word). I have tried to google for the solutions, but can’t work it out. Hope someone can help.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/d/1/d1b599f94a2d079dfc5171cf413965dfd97fc497.png)

curl:  
curl --location ‘[https://www.v2ex.com/api/topics/hot.json](https://www.v2ex.com/api/topics/hot.json)’ \

–header ‘Content-Type: application/json;charset=UTF-8’

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [May 25, 2024, 9:30pm UTC](https://community.postman.com/t/pm-response-text-cant-work-properly-with-chinese/61473/2 "2024-05-25T21:30:58Z")

</div>

Hey @wodefan 👋

Welcome to the Postman community :postman:

Your response is returning JSON, is there a reason you’re trying to assert against the whole response as a string and not target the specific property?

Something like this:

```auto
pm.test("Body matches string", function () {
    pm.expect(pm.response.json()[0].node.title).to.equal("健康");
});

```

---

<div class="post-metadata">

**Author:** ![wodefan](https://avatars.discourse-cdn.com/v4/letter/w/aeb1de/32.png) [@wodefan](https://community.postman.com/u/wodefan)\
**Post date:** [May 26, 2024, 2:23am UTC](https://community.postman.com/t/pm-response-text-cant-work-properly-with-chinese/61473/3 "2024-05-26T02:23:50Z")

</div>

@danny-dainton Thank you for reply.

The example code you post can work properly. I actually know the usage.

I just wonder why `pm.expect(pm.response.text()).to.include("健康")` doesn’t work, cause I’m learning Postman.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [May 26, 2024, 7:11am UTC](https://community.postman.com/t/pm-response-text-cant-work-properly-with-chinese/61473/4 "2024-05-26T07:11:06Z")

</div>

If the more targeted way works and it’s more effective, I’m not sure why the other way would be required.

Without more information or looking deeper into this, I can’t say why that’s not working for you.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [May 28, 2024, 8:58am UTC](https://community.postman.com/t/pm-response-text-cant-work-properly-with-chinese/61473/5 "2024-05-28T08:58:27Z")

</div>

When I console log pm.response.text(), I can see that the Chinese characters are being transposed to the Unicode characters.

So your node.header element for example is showing…

`"\u4e00\u4e2a\u66f4\u597d\u7684\u4e16\u754c\u9700\u8981\u4f60\u6301\u7eed\u5730\u63d0\u51fa\u597d\u95ee\u9898\u3002"`

Instead of…

```auto
"header": "一个更好的世界需要你持续地提出好问题。"

```

Therefore technically the test is correct. That text is not showing in the parsed response.

When you parse it to JSON, it doesn’t transpose the characters, which is why that is working as expected.

---

<div class="post-metadata">

**Author:** ![wodefan](https://avatars.discourse-cdn.com/v4/letter/w/aeb1de/32.png) [@wodefan](https://community.postman.com/u/wodefan)\
**Post date:** [May 28, 2024, 9:36am UTC](https://community.postman.com/t/pm-response-text-cant-work-properly-with-chinese/61473/6 "2024-05-28T09:36:53Z")

</div>

@michaelderekjones You’re right!

The question is that I want to use pm.expect(pm.response.text()).to.include(“健康”) because of its convenience(While using pm.response.json(), I have to designate the exact node by using dot (.) notation).

Is there a solution pm.response.text() can work with Chinese?

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [June 27, 2024, 9:37am UTC](https://community.postman.com/t/pm-response-text-cant-work-properly-with-chinese/61473/7 "2024-06-27T09:37:02Z")

</div>

Closed on June 27, 2024, 9:37am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
