如何通过Jolt转换移除值缺失的对应键?
Solution
To eliminate entries where the corresponding input value is missing, use this two-step Jolt transformation:
Corrected Jolt Spec
[ { "operation": "shift", "spec": { "alldetails": { "classid": "Id_class", "teacherid": "Id_teacher", "schoolid": "Id_school" } } }, { "operation": "shift", "spec": { "*": { "$": "data[].source", "@": "data[#2].value" } } } ]
How It Works
- First Shift Operation: Maps input fields to their corresponding
sourcenames (e.g.,classid→Id_class). Missing fields liketeacheridare automatically excluded from this intermediate result. - Second Shift Operation: Converts each key-value pair from the intermediate object into entries in the
dataarray:$references the current key to set thesourcefield@references the current value to set thevaluefield#2ensuresvalueis added to the same array entry as its matchingsource
Result Output
{ "data": [ { "source": "Id_class", "value": 1 }, { "source": "Id_school", "value": 3 } ] }
Content of the question is from Stack Exchange, asked by Vishavjeet
相关产品推荐
相关产品推荐

