Saturday, 4 September 2021

Wrong encoding in JSON output when working with Hapi, axios and cheerio

There's a website (which I don't manage) with

<meta charset="ISO-8859-1">

I'm building a Hapi server with cheerio, axios that reads some data from this website

This is how the website shows the data I'm getting

website

<span class="name">DÓLAR BNA</span>

I load that html on cheerio as

const response = await axios.get(url2Get);
const $ = cheerio.load(response.data.toString('ISO-8859-1'),{ decodeEntities: false });
// process with cheerio and build/send json response

But I still keep getting this in JSON output

json output

I've tried also installing package iconv-lite and doing

iconv.decode(Buffer.from(title), 'ISO-8859-1');

But no luck yet. Thanks for any advise



from Wrong encoding in JSON output when working with Hapi, axios and cheerio

No comments:

Post a Comment