【问题标题】:How to replace the data of a specific key inside a JSON in BigQuery?如何替换 BigQuery 中 JSON 中特定键的数据?
【发布时间】:2021-02-22 11:14:15
【问题描述】:

我有以下格式的 JSON 数据,我想用一些虚拟值 ('111') 替换 _nanoseconds 的值,而不影响 JSON 结构。

{
  "Category": "Winning",
  "CreatedAt": {
    "_seconds": 1602574892,
    "_nanoseconds": 461491000
  },
  "UpdatedAt": {
    "_seconds": 1602574892,
    "_nanoseconds": 463021000
  }
}

【问题讨论】:

    标签: json google-bigquery


    【解决方案1】:
    select *,
      regexp_replace(json, r'("_nanoseconds": )(\d+)',  '\\1777') as dummy_json
    from `project.dataset.table`     
    

    如果应用于您问题中的样本数据 - 输出是

    【讨论】:

    • 非常感谢您的回答,它与整数值完美配合。但是,我有一些字符串格式,如下所述。你能帮我解决这个问题吗? { "Category": "Winning", "CreatedAt": { "_seconds": 1602574892, "_nanoseconds": "2401:4900:52f0:304a:34cd:93e6:ea31:3cce" }, "UpdatedAt": { "_seconds": 1602574892, "_nanoseconds":"2401:4900:52f0:304a:34cd:93e6:ea31:3cce" } }TIA。另外,请分享参考链接:)
    • 我用([":0-9a-zA-Z ]+)代替(\d+)得到了答案
    猜你喜欢
    • 2015-02-26
    • 1970-01-01
    • 1970-01-01
    • 2021-09-18
    • 2018-04-30
    • 2022-12-05
    • 2012-01-02
    • 1970-01-01
    • 2021-05-26
    相关资源
    最近更新 更多