I have the following inputted Json:
{
"extraFields": {
"language": "french",
"status": {
"comment": "hey"
}
}
}
Using Jolt, I want to achieve the following output:
{
"extraFields": "{"language": "french", "status": {"comment": "hey"}}"
}
Note the backslashes.
I managed to do that with the following Jolt formula:
[
{
"operation": "modify-overwrite-beta",
"spec": {
"extraFields": "=concat('{', '"language": ', '"', @(0,language), '" ,', '"status": ', '{', '"comment": ', '"', @(1,extraFields.status.comment), '"', '}', '}')"
}
}
]
Problem is, fields of extraFields
are optional meaning, some of them might not be inputted.
For example, status
can be omitted or language
or both.
It results, empty values of non-inputted keys.
Is it possible to concatenate only inputted keys?