Convert API response in HTML to JSON form and extract the values in my feature file [closed]

I am trying to convert an API response that comes back in HTML format to JSON format to extract the (auth) values (transId and csfr) and pass to other API to make the request.

  • Tried using JavaScript it needs DOMParser to be imported and could not find a way for it.
  • Tried karate.fromjson () did not work (genAI suggestion)
  • karate.toJson(responseHtml) did not work

HTML Response :

<!DOCTYPE html>
<!-- Build: 1.1.368.1 --><!-- StateVersion: 2.1.1 --><!-- DeploymentMode: Development --><!-- CorrelationId: 52b0f469-b60e-44a1-94cf-d37d65d88d7c --><!-- DataCenter: BL2 --><!-- Slice: 001-000 --><html lang=en><head><link rel=icon href="data:;base64,iVBORw0KGgo="/><script data-container=true nonce="tTR/Kk5G1dCYKmmqwdwlXg==">var CP = {
    "list": []
};
var SETTINGS = {
    "remoteResource": "https://www-teflon.samsclub.com/js/b2c-v19/login.html",
    "retryLimit": 3,
    "trimSpacesInPassword": true,
    "api": "CombinedSigninAndSignup",
    "csrf": "UGxDLzY1aWdtYUNmQ3F4eHNkNTVjaHI0U05hSXdqR1pFalBIYkRNU016dTVsS3pDKzZuVHhWOVY4Yjh1WTdHUzZublJ5SXdNWlVtckUvdmQ2WmIzblE9PTsyMDI1LTAzLTIxVDE4OjM5OjMzLjUzNjcyNTZaO2Y3YWFhemw0SUlZWTVYenBRMy9WUFE9PTt7Ik9yY2hlc3RyYXRpb25TdGVwIjozfQ==",
    "transId": "StateProperties=eyJUSUQiOiI1MmIwZjQ2OS1iNjBlLTQ0YTEtOTRjZi1kMzdkNjVkODhkN2MifQ",
    "pageViewId": "6b8a5204-d387-49f7-be18-f727bd3c432f",
    "suppressElementCss": false,
    "isPageViewIdSentWithHeader": false,
    "allowAutoFocusOnPasswordField": true,
    "pageMode": 1,
    "config": {
        "showSignupLink": "True",
        "sendHintOnSignup": "False",
        "includePasswordRequirements": "true",
        "enableRememberMe": "True",
        "operatingMode": "Email",
        "announceVerCompleteMsg": "True"
    },
    "hosts": {
        "tenant": "/stgtitan.onmicrosoft.com/B2C_1A_SignInWebWithKmsi",
        "policy": "B2C_1A_SignInWebWithKmsi",
        "static": "https://stg.titan.samsclub.com/static/"
    },