如何使用JOLT按JSON键值对排序?适配问答数量可变场景
基于JOLT实现动态问答数据按序列升序排序
需求:对JSON对象的键值对数据按questionSequence字段升序排序,同时适配问答数量不固定(可动态增减)的场景。
输入示例
{ ".0.answer": "In tag functionality ", ".0.question": "Provide a brief description", ".0.questionSequence": 1, ".1.answer": "In Git if we want to know", ".1.question": "Use Case Description ", ".1.questionSequence": 3, ".2.answer": "In Git if we want to know PIT", ".2.question": "Business Justification ", ".2.questionSequence": 2 }
期望输出示例
{ ".0.answer": "In tag functionality ", ".0.question": "Provide a brief description", ".0.questionSequence": 1, ".2.answer": "In Git if we want to know PIT", ".2.question": "Business Justification ", ".2.questionSequence": 2, ".1.answer": "In Git if we want to know", ".1.question": "Use Case Description ", ".1.questionSequence": 3 }
JOLT配置方案
[ { "operation": "shift", "spec": { "*": "*questionSequence" } }, { "operation": "sort" } ]
内容的提问来源于stack exchange,提问作者self lab
相关产品推荐
相关产品推荐

