首页
学习
活动
专区
圈层
工具
发布

Jolt变换
EN

Stack Overflow用户
提问于 2018-01-17 00:21:00
回答 1查看 748关注 0票数 0

我正在尝试为下面的输入写一个jolt转换-

代码语言:javascript
复制
{ 
 "restaurantId": "ZZ4ORJDY3E",  
 "chainId": "a-b"
}

预期输出为-

代码语言:javascript
复制
{
 "ZZ4ORJDY3E" : {
   "key" : "ZZ4ORJDY3E",
   "start" : "a",
   "end" : "b"
  }
}

我的规格是-

代码语言:javascript
复制
[
  {
    "operation": "shift",
    "spec": {
      "@restaurantId": "@restaurantId.key",
      "chainId": {
        "*-*": {
          "$(0,1)": "@restaurantId.start",
          "$(0,2)": "@restaurantId.end"
        }
      }
    }
  }
]

规范没有按照预期的输出进行转换。我想学习如何在字符串解析器中使用属性。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-20 01:12:01

等级库

代码语言:javascript
复制
[
  {
    "operation": "shift",
    "spec": {
      "restaurantId": {
        // match any value of restaurantId
        "*": {
          // write the value to of the key $ to the output
          // where the output is the "value of the key".key
          // kinda hokey
          "$": "&.key"
        }
      },
      "chainId": {
        "*-*": {
          // write each part of the chainId to the output
          //  at the value of restaurantId from back up the tree
          "$(0,1)": "@(3,restaurantId).start",
          "$(0,2)": "@(3,restaurantId).end"
        }
      }
    }
  }
]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48285655

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档