How to dismiss html elements from JSON payload

I’m using WhatIsMyMMR Api to get mmr data of my lol account
URL: https://eune.whatismymmr.com/api/v1/summoner?name=karimawi
Part I’m getting command data from:

    "ranked": {
        "avg": 1161,
        "err": 86,
        "warn": false,
        "summary": "Approximately <b>Bronze I</b><br><br><span class=\"symbol--micro\"></span>MMR resembles the <b>bottom 49%</b> of summoners in Bronze I",
        "closestRank": "Bronze I",
        "percentile": 49
    }
}

I wrote this:

`$(eval const api = $(urlfetch json https://eune.whatismymmr.com/api/v1/summoner?name=karimawi); `Ranked Solo MMR: ${api.ranked.avg}, ${api.ranked.summary}`)

But as you may have guessed already, the “summary” part has HTML elements in there so it appears in twitch chat like this: Ranked Solo MMR: 1161, Approximately <b>Bronze I</b><br><br><span class="symbol--micro"></span>MMR resembles the <b>bottom 49%</b> of summoners in Bronze I

What I need as a response is smth like this: Ranked Solo MMR: 1161, Approximately Bronze I, MMR resembles the bottom 49% of summoners in Bronze I (note the comma after Bronze I)

How can I remove the HTML elements whilst adding a comma before MMR resembles the.... while making it suitable for other ranks cuz idk how someone will help but if some logic would be involved it would only work with shitty Bronze I payload like mine, right? afaik cause I know so very little about coding in general, knowing that ranks like Master, Grandmaster and Challenger wont have a division number (I, II, III, IV).

If you want more details about the API check:
https://dev.whatismymmr.com/ (says the summary response will deprecated in v2 T_T)

Hey @karimawi!

It’s easily done with .replace() and some Regex, and assuming there’ll always be a <span> before the spot you want the comma to be placed, we can use that to add it at the right place:

$(eval const api = $(urlfetch json https://eune.whatismymmr.com/api/v1/summoner?name=karimawi); `Ranked Solo MMR: ${api.ranked.avg}, ${api.ranked.summary.replace('</span>', ', ').replace(/(<([^>]*)>)/gi, '')}`)
2 Likes

Works great, thanks a lot

1 Like

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