Converting an array into a simplified JSON object

Does anyone have a slick way of converting an array where each element is an array of length 2, that contains the key at index 0 and value at index 1, into a JSON object. This is what the original looks like:

{
    "HeadersIn": [
        [
            "Host",
            "example.com"
        ],
        [
            "Accept",
            "*/*"
        ],
        [
            "Connection",
            "keep-alive"
        ],
        [
            "Cookie",
            ""
        ],
        [
            "User-Agent",
            "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/600.7.12 (KHTML, like Gecko) Version/8.0.7 Safari/600.7.12"
        ],
        [
            "Accept-Language",
            "en-us"
        ],
        [
            "Referer",
            "https://example.com/"
        ],
        [
            "Accept-Encoding",
            "gzip, deflate"
        ]
    ]
}

Output should be

{
    "HeadersIn": {
        "Host": "example.com",
        "Accept": "*/*",
        "Connection": "keep-alive",
        "Cookie": "",
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/600.7.12 (KHTML, like Gecko) Version/8.0.7 Safari/600.7.12",
        "Accept-Language": "en-us",
        "Referer": "https://example.com/",
        "Accept-Encoding": "gzip, deflate"
    }
}
1 UpGoat

@RicoSuave, this is a great use of the JavaScript Object.fromEntries() function! This is specific to this array format where the keys are the zero index and the values are the first index.

See this example code:

const arr = [
  ["0", "a"],
  ["1", "b"],
  ["2", "c"],
];
const obj = Object.fromEntries(arr);
console.log(obj); // { 0: "a", 1: "b", 2: "c" }

(source)

In Cribl Stream, use an Eval function and set the value of the new field to Object.fromEntries(HeadersIn).

1 UpGoat