我需要为这个转换写一个震动规范 输入:

[
  {
    "value": "My name is-Yash:Jain",
    "encoding": [
      {
        "enc": " ",
        "dec": "space"
      },
      {
        "enc": "-",
        "dec": "minus"
      },
      {
        "enc": ":",
        "dec": "colon"
      }
    ]
  }
]

输出应为

{
  "value": "MyspacenamespaceisminusYashcolonJain"
}

基本上,我需要遍历整个编码列表,并用dec替换enc的每个值实例.

我已经try 了以下转换:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "t1": "=split(' ',@(1,value))",
        "t2": "=join('space',@(1,t1))",
        "t3": "=split('-',@(1,t2))",
        "t4": "=join('minus',@(1,t3))",
        "t5": "=split(':',@(1,t4))",
        "t6": "=join('colon',@(1,t5))"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "t6": "value"
      }
    }
  }
]

推荐答案

回来--即使是很短的时间--振作起来也是件好事:).我可能生疏了,所以我不确定这是否是最好的解决方案,但我能够使用下面的规范动态地使它工作.这很难解释,而且注释可能会令人困惑,这就是为什么我建议首先逐个运行每个操作,以了解规范获得所需转换所需的步骤.

[
  //split the value string into array of characters
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "value": "=split('',@(1,value))"
      }
    }
  },
    // This is the magic operation, it basically groups unique characters
  //from the enc values and from the array above. each
  // unique character will have placeholder values and indexes where there is
  // a match from the value array char. based on how the shift is organized, 
  // the placeholder at index 0 is the correct placeholder value.
  {
    "operation": "shift",
    "spec": {
      "*": {
        "encoding": {
          "*": {
            "dec": "[&3].@1,enc.placeholder[]"
          }
        },
        "value": {
          "*": {
            "@": "[&3].@1.placeholder[]",
            "$": "[&3].@1.indexes[]"
          }
        }
      }
    }
  },
  //loop through each unique character from above, then loop through each 
  //matched index and create new array where the placeholder[0] is placed
  //at each matched index so that we can maintain the same order 
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "indexes": {
            "*": {
              "@2,placeholder[0]": "[&4].value[@1]"
            }
          }
        }
      }
    }
  },
  // join the value array from above to get the final value string
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "value": "=join('',@(1,value))"
      }
    }
  }
]

@BarbarosÖzhan,请随意添加或修改\更改您认为合适的规格.

Json相关问答推荐

Vega图表计数聚合如果数据值为空数组则不显示任何内容,如何解决此问题?

我发现GoFr响应总是包含在数据字段中,如何返回自定义响应?

使用Jolt v.0.1.1向每个json元素添加一个键-值对

如何在Swift中使用JSON编码器的泛型

419(未知状态)使用laravel处理PUT请求

当由.sh脚本执行时,AWS查询字符串不会提取任何数据

Jolt Spec 跳过数组中的第一个元素

根据值过滤输入的JSON并使用它准备预期的输出

使用Powershell将JSON文件加载到SQL Server表格

从 PySpark 中的复杂 JSON 文件中高效清除 HTML 实体

boost::json::value 的大括号初始化将其从对象转换为数组

C# 合并 2 个几乎相同的 JSON 对象

从 JSON 对象中删除键值对

如何在返回对象的 Spring MVC @RestController @ResponseBody 类中响应 HTTP 状态代码?

如何为名称/值 struct 创建 JSON 模式?

Rails 中奇怪的 JSON Javascript 问题

嵌套 JSON:如何向对象添加(推送)新项目?

Jackson JSON序列化,通过级别定义避免递归

使用 C# 调用 json

Backbone.js 模型与集合