[英]JSONata data mapping template
I'm starting to use JSONata for data transformation and I was wondering if there exists a way to have a file which contains values transformation for some fields in json file.我开始使用 JSONata 进行数据转换,我想知道是否有一种方法可以让文件包含 json 文件中某些字段的值转换。
I will have to do multiple transformation types, but most cases will be to translate a field value from "A" to "B" for example and I will be easier to do that in a file in order to not create new versions of data transformation and just will be necessary to create a new entry in this file.我将不得不进行多种转换类型,但大多数情况是将字段值从“A”转换为“B”,我将更容易在文件中执行此操作,以免创建新版本的数据转换并且只需要在此文件中创建一个新条目。
Regards问候
You can use $lookup
to perform simple mappings.您可以使用$lookup
来执行简单的映射。 For example, with the following JSON:例如,使用以下 JSON:
{
"mapping": [
{ "a": "a1" },
{ "b": "b1" }
],
"values": [
"a", "b"
]
}
You can map the values
using:您可以使用 map values
:
values.$lookup($$.mapping, $)
In which case the result will be:在这种情况下,结果将是:
[
"a1",
"b1"
]
Alternatively you can look at $sift
which will allow you to write a function to sift through the mappings.或者,您可以查看$sift
,它允许您编写 function 来筛选映射。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.