给定多个对象时如何提供输入以震撼 [英] How to provide input to jolt when multiple objects are given

查看:61
本文介绍了给定多个对象时如何提供输入以震撼的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将转换应用于具有以下格式记录的json文件(不是数组,而是多个对象).我想提供一个具有以下输入格式并应用了transfornation后的文件.想将其保存在某个文件夹中. 例如:

How to apply transformation to the json file having records in the following format (not array, just multiple objects). I want to provide a file with following input format and after applying transfornation.Want to get it saved in some folder. example:

输入记录格式

    {
     "name": "adam",
     "age": 12,
     "city": "australia"
   }
   {
     "name": "adam",
     "age": 12,
     "city": "australia"
   }
   {
     "name": "adam",
     "age": 12,
     "city": "australia"
   }
   {
     "name": "adam",
     "age": 12,
     "city": "australia"
   }
   {
     "name": "adam",
     "age": 12,
     "city": "australia"
   }
   {
     "name": "adam",
     "age": 12,
     "city": "australia"
   }
   .....

所需的输出记录格式

   {
     "fname": "adam",
     "age": 12,
     "city": "australia"
   }
   {
     "fname": "adam",
     "age": 12,
     "city": "australia"
   }
   {
     "fname": "adam",
     "age": 12,
     "city": "australia"
   }
   {
     "fname": "adam",
     "age": 12,
     "city": "australia"
   }
   {
     "fname": "adam",
     "age": 12,
     "city": "australia"
   }
   {
     "fname": "adam",
     "age": 12,
     "city": "australia"
   }
   // Just changing the name key to fname
   .....

推荐答案

由于您标记了apache-nifi,因此我假设您要为此使用Apache NiFi中的JOLT处理器之一.在这种情况下,JoltTransformJSON将不起作用,因为正如daggett所说的,它期望有效的JSON.但是,JsonTreeReader中的JSON解析器更为宽松,因此您可以将JoltTransformRecord与JsonTreeReader和以下规范一起使用:

Since you tagged apache-nifi I assume you want to use one of the JOLT processors in Apache NiFi for this. In this case JoltTransformJSON won't work because it expects valid JSON as daggett said. However the JSON parser in JsonTreeReader is more lenient, so you can use JoltTransformRecord with a JsonTreeReader and the following spec:

[
  {
    "operation": "shift",
    "spec": {
      "name": "fname",
      "*": "&"
    }
  }
]

尽管没有有效的JSON就不能漂亮地打印" JSON,但是可以将JsonRecordSetWriter的Output Grouping属性设置为One Line Per Object.这将为您提供类似以下内容的输入:

Although you can't "pretty print" the JSON without it being valid JSON, you can set the Output Grouping property on the JsonRecordSetWriter to One Line Per Object. That will give you input something like:

{"fname":"adam","age":12,"city":"australia"}
{"fname":"adam","age":12,"city":"australia"}
{"fname":"adam","age":12,"city":"australia"}
{"fname":"adam","age":12,"city":"australia"}
{"fname":"adam","age":12,"city":"australia"}
{"fname":"adam","age":12,"city":"australia"}

这篇关于给定多个对象时如何提供输入以震撼的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆