# Encoding or charset issue with JSON payload

**URL:** <https://forum.ionicframework.com/t/encoding-or-charset-issue-with-json-payload/58507>\
**Category:** ionic-v3\
**Created:** [July 25, 2016, 12:16pm UTC](https://forum.ionicframework.com/t/encoding-or-charset-issue-with-json-payload/58507 "2016-07-25T12:16:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![unvadim](https://avatars.discourse-cdn.com/v4/letter/u/d78d45/32.png) [@unvadim](https://forum.ionicframework.com/u/unvadim)\
**Post date:** [July 25, 2016, 12:16pm UTC](https://forum.ionicframework.com/t/encoding-or-charset-issue-with-json-payload/58507/1 "2016-07-25T12:16:04Z")

</div>

I have an ionic application that fetches data from a remote web server (json). The response is UTF-8 and has some French characters. The issue is that these French characters are not displayed correctly in the app.  
i.e. Synthétique is shown as SynthÃ©tique.  
the é in utf-8 has code C3A9 (two bytes) which matches Ã and © in iso-8859-1 which seems to imply that there enconding from UTF-8 to iso-8859-1.  
What I am doing wrong here? or what do I need to do to get the French characters correctly displayed.

---

<div class="post-metadata">

**Author:** ![jimmip](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@jimmip](https://forum.ionicframework.com/u/jimmip)\
**Post date:** [July 25, 2016, 10:26pm UTC](https://forum.ionicframework.com/t/encoding-or-charset-issue-with-json-payload/58507/2 "2016-07-25T22:26:41Z")

</div>

You can use these tools [JSON Formatter](http://jsonformatter.org) or [JSON Viewer](http://codebeautify.org/jsonviewer) to validate json data.

---

<div class="post-metadata">

**Author:** ![kierandes](https://avatars.discourse-cdn.com/v4/letter/k/4491bb/32.png) [@kierandes](https://forum.ionicframework.com/u/kierandes)\
**Post date:** [January 9, 2018, 11:42am UTC](https://forum.ionicframework.com/t/encoding-or-charset-issue-with-json-payload/58507/3 "2018-01-09T11:42:40Z")

</div>

Did you solve it in the end? Having similar problems getting data that has formatting and its lost.

---

<div class="post-metadata">

**Author:** ![unvadim](https://avatars.discourse-cdn.com/v4/letter/u/d78d45/32.png) [@unvadim](https://forum.ionicframework.com/u/unvadim)\
**Post date:** [January 9, 2018, 12:07pm UTC](https://forum.ionicframework.com/t/encoding-or-charset-issue-with-json-payload/58507/4 "2018-01-09T12:07:51Z")

</div>

Yes, I had to rely on a hack and do manual conversion on the client side. I was passing each incoming French string through the function below:

```auto
export class Hack {

    public static fromUTF8String(intpuStr) {
        let data = [];

        for (let i = 0; i < intpuStr.length; ++i) {
            data.push(intpuStr.charCodeAt(i));
        }

        var str = '',
            i;

        for (i = 0; i < data.length; i++) {
            var value = data[i];

            if (value < 0x80) {
                str = str.concat(String.fromCharCode(value));
            } else if (value > 0xBF && value < 0xE0) {
                str = str.concat(String.fromCharCode((value & 0x1F) << 6 | data[i + 1] & 0x3F));
                i += 1;
            } else if (value > 0xDF && value < 0xF0) {
                str = str.concat(String.fromCharCode((value & 0x0F) << 12 | (data[i + 1] & 0x3F) << 6 | data[i + 2] & 0x3F));
                i += 2;
            } else {
                // surrogate pair
                var charCode = ((value & 0x07) << 18 | (data[i + 1] & 0x3F) << 12 | (data[i + 2] & 0x3F) << 6 | data[i + 3] & 0x3F) - 0x010000;

                str = str.concat(String.fromCharCode(charCode >> 10 | 0xD800, charCode & 0x03FF | 0xDC00));
                i += 3;
            }
        }

        return str;
    }
}

```

This is not a solution I did come-up with but found it online long time ago, can’t find the original.

---

<div class="post-metadata">

**Author:** ![kierandes](https://avatars.discourse-cdn.com/v4/letter/k/4491bb/32.png) [@kierandes](https://forum.ionicframework.com/u/kierandes)\
**Post date:** [January 17, 2018, 9:38pm UTC](https://forum.ionicframework.com/t/encoding-or-charset-issue-with-json-payload/58507/5 "2018-01-17T21:38:08Z")

</div>

Thanks! Must try that!

---

<div class="post-metadata">

**Author:** ![ahboyboy](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@ahboyboy](https://forum.ionicframework.com/u/ahboyboy)\
**Post date:** [August 17, 2018, 12:01am UTC](https://forum.ionicframework.com/t/encoding-or-charset-issue-with-json-payload/58507/6 "2018-08-17T00:01:50Z")

</div>

Thanks, this hack works for me!! You saved my day^^
