API : HTML special characters in JSON

boeing_605 years ago

Hello everyone,

I wanted to ask if it was an expected behavior of the API to return some characters in their HTML special codes ?

For example, I have a geofence which contains an apostrophe " ' " in its name.
In the database (MySQL) and the Web interface it's properly stored and displayed, but when I get it through the API,
I get

'

in the JSON instead of the apostrophe.

I got this problem with some other characters like double quote or <. But not with other like ©, #, É ... for some reason.
It doesn't matter if I have inserted the data via the website or the API in the first place.

Have a good day !

Traccar version : 4.10 (same problem with 4.9 and with default database)
OS : Debian 10

Anton Tananaev5 years ago

That's expected behavior.

boeing_605 years ago

Thanks for the response !

Then how can we know which HTML characters will be sent as a code ? Is their a list ?

Sorry if it's a common asking.

Anton Tananaev5 years ago

Just decode all encoded characters.

boeing_605 years ago

Okay, I found two functions in PHP that should does the trick :
https://www.php.net/manual/fr/function.htmlspecialchars-decode.php
https://www.php.net/manual/fr/function.html-entity-decode.php

Thanks for the help.

Have a nice week-end !