当前位置: 首页 > 知识库问答 >
问题:

将JSON拆分为更小的部分-更新2021/06/08

华安民
2023-03-14

我在收集JSON的Nifi中获得了一些数据,但是它需要插入的表具有不同的格式。

我很难将JSON结构分解成更小的部分--第二个部分似乎是两三个部分的转变。有什么想法能让我进入下一步吗?

[
  {
    "inverterId": "Id159946.3",
    "timestamp": "2021-06-03 10:35:00.000",
    "COS_PHI": 0.998,
    "E_DAY": 85.6419916666667,
    "E_INT": 1.9674496666666663,
    "E_INT_N": 0.05,
    "E_TOTAL": 1142,
    "ERROR1": 0,
    "F_AC": 50.05200000000001,
    "I_AC": 96.96799999999999,
    "I_AC1": 32.322,
    "I_AC2": 32.318,
    "I_AC3": 32.327999999999996,
    "I_DC": 42.013999999999996,
    "I_DC1": 14.184000000000001,
    "I_DC1_1": 7.191999999999999,
    "I_DC1_2": 6.869999999999999,
    "I_DC2": 13.898,
    "I_DC2_1": 7.194,
    "I_DC2_2": 6.593999999999999,
    "I_DC3": 13.931999999999999,
    "I_DC3_1": 7.03,
    "I_DC3_2": 6.798,
    "I_DC4": null,
    "I_DC4_1": null,
    "I_DC4_2": null,
    "I_DC5": null,
    "I_DC5_1": null,
    "I_DC5_2": null,
    "OT_AC_TOTAL": 94,
    "P_AC": 23609.395999999997,
    "P_AC_N": 0.62,
    "P_DC": 24096.873999999996,
    "Q_AC": 953.1700000000001,
    "QS_CI": 100,
    "QS_RX": 1116,
    "QS_TX": 1116,
    "R_ISO": 20000,
    "STATE1": 0,
    "STATE2": 131073,
    "T_WR": 35.394,
    "U_AC": 243.76000000000002,
    "U_AC1": 243.628,
    "U_AC2": 244.3,
    "U_AC3": 243.35199999999998,
    "U_DC": 573.1573333333333,
    "U_DC1": 570.628,
    "U_DC2": 572.452,
    "U_DC3": 576.3919999999999,
    "U_DC4": null,
    "U_DC5": null,
    "systemKey": "K9V2Q"
  },
  {
    "inverterId": "Id159946.2",
    "timestamp": "2021-06-03 10:40:00.000",
    "COS_PHI": 0.998,
    "E_DAY": 118.47494700000001,
    "E_INT": 1.7862204999999998,
    "E_INT_N": 0.03,
    "E_TOTAL": 1270,
    "ERROR1": 0,
    "F_AC": 50.038,
    "I_AC": 91.154,
    "I_AC1": 30.296,
    "I_AC2": 30.392000000000003,
    "I_AC3": 30.465999999999998,
    "I_DC": 31.753999999999998,
    "I_DC1": 4.226,
    "I_DC1_1": 3.852,
    "I_DC1_2": 0.378,
    "I_DC2": 4.088,
    "I_DC2_1": 4.074,
    "I_DC2_2": 0.04000000000000001,
    "I_DC3": 8.074,
    "I_DC3_1": 4.138,
    "I_DC3_2": 3.898,
    "I_DC4": 7.584,
    "I_DC4_1": 3.806,
    "I_DC4_2": 3.7119999999999997,
    "I_DC5": 7.782,
    "I_DC5_1": 3.972,
    "I_DC5_2": 3.7439999999999998,
    "OT_AC_TOTAL": 79,
    "P_AC": 21434.645999999997,
    "P_AC_N": 0.34,
    "P_DC": 21971.543999999998,
    "Q_AC": 901.4119999999999,
    "QS_CI": 100,
    "QS_RX": 1119,
    "QS_TX": 1119,
    "R_ISO": 20000,
    "STATE1": 0,
    "STATE2": 131073,
    "T_WR": 41.766000000000005,
    "U_AC": 240.552,
    "U_AC1": 241.614,
    "U_AC2": 239.54,
    "U_AC3": 240.50199999999998,
    "U_DC": 692.9512,
    "U_DC1": 806.782,
    "U_DC2": 599.358,
    "U_DC3": 631.958,
    "U_DC4": 817.722,
    "U_DC5": 608.936,
    "systemKey": "K9V2Q"
  },
  {
    "inverterId": "Id159946.3",
    "timestamp": "2021-06-03 10:40:00.000",
    "COS_PHI": 0.998,
    "E_DAY": 86.9375756666667,
    "E_INT": 1.295584,
    "E_INT_N": 0.03,
    "E_TOTAL": 1143,
    "ERROR1": 0,
    "F_AC": 50.038,
    "I_AC": 65.03800000000001,
    "I_AC1": 21.674,
    "I_AC2": 21.678,
    "I_AC3": 21.686,
    "I_DC": 28.126,
    "I_DC1": 9.486,
    "I_DC1_1": 4.824,
    "I_DC1_2": 4.548,
    "I_DC2": 9.234,
    "I_DC2_1": 4.822,
    "I_DC2_2": 4.2940000000000005,
    "I_DC3": 9.406,
    "I_DC3_1": 4.77,
    "I_DC3_2": 4.524,
    "I_DC4": null,
    "I_DC4_1": null,
    "I_DC4_2": null,
    "I_DC5": null,
    "I_DC5_1": null,
    "I_DC5_2": null,
    "OT_AC_TOTAL": 94,
    "P_AC": 15547.008,
    "P_AC_N": 0.41,
    "P_DC": 15971.436000000002,
    "Q_AC": 810.6179999999999,
    "QS_CI": 100,
    "QS_RX": 1122,
    "QS_TX": 1122,
    "R_ISO": 20000,
    "STATE1": 0,
    "STATE2": 131073,
    "T_WR": 35.664,
    "U_AC": 242.69133333333335,
    "U_AC1": 242.72,
    "U_AC2": 243.30200000000002,
    "U_AC3": 242.05199999999996,
    "U_DC": 566.1546666666667,
    "U_DC1": 561.5440000000001,
    "U_DC2": 567.3480000000001,
    "U_DC3": 569.572,
    "U_DC4": null,
    "U_DC5": null,
    "systemKey": "K9V2Q"
  }
]
[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "timestamp": "[&1].timestamp",
        "inverterId": "[&1].inverterId",
        "systemKey": "[&1].systemKey",
        "I_DC*_*": "[&1].&"
      }
    }
  }
]
[
  {
    "timestamp": "2021-06-03 10:35:00.000",
    "systemKey": "K9V2Q",
    "inverterId": "Id159946.3",
    "stringId": "I_DC1_1",
    "value": 7.191999999999999  
  },{
    "timestamp": "2021-06-03 10:35:00.000",
    "systemKey": "K9V2Q",
    "inverterId": "Id159946.3",
    "stringId": "I_DC1_2",
    "value": 6.869999999999999
  },{
    "timestamp": "2021-06-03 10:35:00.000",
    "systemKey": "K9V2Q",
    "inverterId": "Id159946.3",
    "stringId": "I_DC2_1",
    "value": 7.194  
  },{
    "timestamp": "2021-06-03 10:35:00.000",
    "systemKey": "K9V2Q",
    "inverterId": "Id159946.3",
    "stringId": "I_DC2_2",
    "value": 6.593999999999999  
  }
]
[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "I_DC*_*": "[].&"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "$": "[#3].stringId",
          "@": "[#3].value"
        }
      }
    }
  }
]

产出:

[
  {
    "stringId": "I_DC1_1",
    "value": 7.191999999999999
  },
  {
    "stringId": "I_DC1_2",
    "value": 6.869999999999999
  },
  {
    "stringId": "I_DC2_1",
    "value": 7.194
  }
]

共有1个答案

皮献
2023-03-14
[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "timestamp": "[&1].timestamp",
        "inverterId": "[&1].inverterId",
        "systemKey": "[&1].systemKey",
        "I_DC*_*": "[&1].&"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "timestamp": "[&1].timestamp",
        "inverterId": "[&1].inverterId",
        "systemKey": "[&1].systemKey",
        "*": "[&1].keysToPivot.&"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "keysToPivot": {
          "*": {
            "$": "[&3].[#2].stringId",
            "@": "[&3].[#2].value",
            "@(2,timestamp)": "[&3].[#2].timestamp",
            "@(2,inverterId)": "[&3].[#2].inverterId",
            "@(2,systemKey)": "[&3].[#2].systemKey"
          }
        }
      }
    }
  }
]

请测试它,让我知道如果有任何问题。

 类似资料:
  • 我们使用Golang实现了一个包含CRUD的REST API,在Update服务中,客户端可以发送部分JSON(包括更改的字段),我们需要处理这些更改对实体的更新。 逻辑上,我们需要通过Id从DB获取实体到结构,然后将有效载荷json解封到另一个结构并更新实体。 这是一个简单的例子,实际上它可能是一个嵌套的结构和嵌套的json,我们如何用golang或事件其他语言(如Java,.NET)来处理这种

  • 我们要求当前在SOLR中索引的文档可能需要定期进行部分更新。更新可以是。添加新字段B。更新现有字段的内容。我们模式中的一些字段是存储的,其他的没有。 Solr4确实允许这样做,但必须存储所有字段。见Update a new field to existing document和http://solr.pl/en/2012/07/09/solr-4-0-partial-documents-updat

  • 基本上,我要问的是给定一个正方形2D阵列和一个有效的补丁大小(2D子阵列的大小),我将如何做到这一点。最终,我不需要以任何方式存储子阵列,我只需要找到每个子阵列的中值并将它们存储在一个一维阵列中。中值和存储到新阵列对我来说很简单,我只是不知道如何处理原始2D阵列并正确拆分它。我已经尝试了几次,但一直出现越界错误。我有一个4x4: 我需要像这样拆分它 < code>[1,2] [3,4] [2,3]

  • 问题内容: 如何使用NEST2部分更新记录? 我正在寻找一个模拟请求:POST / erection / shop / 1 / _update {“ doc”:{“ new”:“ 0”}} 而无需重新 创建新记录。不幸的是,我没有在www.elastic.co/guide/en/elasticsearch/client/net- api/current/index.html中找到有关更新的任何信息

  • 问题内容: 我想做如下的部分更新。添加一些新字段,例如Bytes_In和Bytes_Out。并且还运行脚本来更新使用脚本从其他字段派生的字段。 脚本session-duration-script.groovy在/ config / scripts路径下。 当我运行上述更新查询时,出现此错误 请让我知道有办法实现这种更新。 问题答案: 由于错误状态,您不能同时使用和。我的建议是修改脚本,以添加所需的

  • 问题是关于阿克卡演员图书馆。A想把一个大任务分成几个小任务,然后把它们的结果合并成一个“大”结果。这将给我更快的计算利润。如果较小的任务是独立的,则可以并行计算它们。 假设我们需要这样计算。函数非常耗时,因此在一个线程中多次使用它并不理想。 问题来了。 如何分派任务、收集结果,然后折叠它们,所有这些都使用akka actors?Akka已经提供了这样的功能,还是我需要自己实现?这种方法的最佳实践是