【问题标题】:json parse. Extract 2 values from multiple records and merge into one cell, with array formulajson解析。从多条记录中提取2个值并合并到一个单元格中,使用数组公式
【发布时间】:2022-06-26 13:22:44
【问题描述】:

我正在尝试使用公式从表格单元格 A1:A 中的每个“哈希”中提取值,并将它们连接到单元格 B1:B 中,用逗号分隔

https://docs.google.com/spreadsheets/d/1i2qLX-BfZ6ZpWNzpgAVHsNSTG8HjwbhSFVfqtp8bMhc/edit?usp=sharing

JSON

A1

{
"2Qk1xsOqhlxUe5d3fiJVcXgBLaBODegmo":{
"hash":"2Qk1xsOqhlxUe5d3fiJVcXgBLaBODegmo",
"name":"logo2.png",
"description":"",
"type":"image/png",
"path":"/logo2.png",
"size":"13 KB"
},
"1W2HdCGmeMLz1u0kzvxdUhGyEwIUlMD-s":{
"hash":"1W2HdCGmeMLz1u0kzvxdUhGyEwIUlMD-s",
"name":"logo.png",
"description":"",
"type":"image/png",
"path":"/logo.png",
"size":"29 KB"
}
}

A2

{
"5Qk1xsOqhlxUe5d3fiJVcXgBLaBODegmo":{
"hash":"5Qk1xsOqhlxUe5d3fiJVcXgBLaBODegmo",
"name":"logo2.png",
"description":"",
"type":"image/png",
"path":"/logo3.png",
"size":"13 KB"
},
"4W2HdCGmeMLz1u0kzvxdUhGyEwIUlMD-s":{
"hash":"4W2HdCGmeMLz1u0kzvxdUhGyEwIUlMD-s",
"name":"logo.png",
"description":"",
"type":"image/png",
"path":"/logo4.png",
"size":"29 KB"
}
}

提取值(哈希)

B1

2Qk1xsOqhlxUe5d3fiJVcXgBLaBODegmo,1W2HdCGmeMLz1u0kzvxdUhGyEwIUlMD 

B2

5Qk1xsOqhlxUe5d3fiJVcXgBLaBODegmo,4W2HdCGmeMLz1u0kzvxdUhGyEwIUlMD

【问题讨论】:

    标签: json regex google-sheets array-formulas re2


    【解决方案1】:

    试试:

    =INDEX(REGEXREPLACE(TRIM(FLATTEN(QUERY(TRANSPOSE(IFNA(REGEXREPLACE(SPLIT(REGEXEXTRACT(
     REGEXREPLACE(A2:A, "[""\{\}\n ]|-s", ), "hash:.*"), "hash:", ), 
     "name.*", ))),,9^9))), " |,$", ))
    

    【讨论】:

    • 谢谢!但是由于某种原因,如果 json 只有 1 个对象,它将在末尾用逗号提取
    • @O1R 已修复,立即尝试
    【解决方案2】:

    使用regexextract(),像这样:

    =arrayformula( 
      textjoin( 
        ",", 
        true, 
        iferror( 
          regexextract( 
            query( 
              transpose( split(A2, "," & char(10), true, true) ), 
              "where Col1 contains 'hash' ", 0 
            ), 
            "hash"":""(\w+)"
          ) 
        ) 
      ) 
    )
    

    【讨论】:

    • 谢谢!但不幸的是,只检索到一个值。我尝试使用这个公式=REGEXEXTRACT(A3,"""hash"":""(.+?)"""),但它只提取一个值。
    • 要从一个单元格中提取多个值,请使用我上面给出的公式。要从整列中提取多个值,请使用 @player0 的公式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-25
    相关资源
    最近更新 更多