I need to use a header value AcceptLanguage
as a reference for a key value in a mapping response.
Given the following REST response
{
"data": {
"item": {
"details": {
"latest": {
"variation": {
"id": "args id",
"props": [
{
"key": "variant-name",
"val": {
"en-US": "en us version of the val"
}
}
]
}
}
}
}
}
}
And the following variables
{
"$args": {
"id": "arg id"
},
"$this": {
"headers": {
"AcceptLanguage": "en-US"
}
}
}
And the following mapping
$.data.item.details.latest.variation {
id
props -> first.val {
key: $this.headers.AcceptLanguage
}
}
I currently get the following response
{
"id": "args id",
"key": "en-US"
}
However, I am wanting it to be
{
"id": "args id",
"key": "en us version of the val"
}
How can I use the header as a reference to a specific field in the response object?
Things I have tried:
$.data.item.details.latest.variation {
id
props -> first.val {
key: $($this.headers.AcceptLanguage)
}
}
results in
{
"id": "args id",
"key": "en-US"
}
$.data.item.details.latest.variation {
id
props -> first.val {
key: "$($this.headers.AcceptLanguage)"
}
}
fails with error Property ."$($this.headers.AcceptLanguage)" not found in object
In a related question, I actually need to have the header be Accept-Language
, but I haven’t been able to figure out how to escape the -
character.