在 Excel 中使用 Power Query 解析 JSON 的方式与 FetchJson 在 Google 工作表中的解析方式相同

Parse JSON with Power Query in Excel in the same way FetchJson does in Google sheets

我想使用具有以下结构的 Power Query 在 Excel 中削减 JSONs

这里是 link: https://sum-app.net/projects/15222520210510875/download_data/kumu_json

我可以在 Google sheet 中使用 FetchJson 执行以下操作,但我没有运气使用 Ecexls Power 查询执行相同的操作

如何在 Excel 中使用 Power Query 执行此操作?

在此先感谢您对此的帮助

//获取JSON元素的数据 var data=FetchJSON(jsonlink ,"|", "元素");

//获取Json连接数据 var data=FetchJSON(jsonlink ,"|", "connections");

 //get Json Data for element
function FetchJSON(jsonlink ,separator, what) {

// Set Fetch Variables
  var response     = UrlFetchApp.fetch(jsonlink);
  var responseText = response.getContentText();
  var responseJson = JSON.parse(responseText);

  if(what=="elements"){
  let myDico = new Map();
  responseJson.elements.forEach(function(key){
    Object.keys(key).forEach(function(item){
       myDico.set(item,'')
    })
  })
  var elementKeys = []
  myDico.forEach(function(value, key) {
    elementKeys.push(key)
  });
  var data = responseJson.elements.map(e => elementKeys.map(f => {
      return e[f] instanceof Array ? e[f].join(separator) : e[f];
  })); 
  data.unshift(elementKeys);
  
  } 
  else if(what=="connections"){
   let myDico2 = new Map()
   responseJson.connections.forEach(function(key){
    Object.keys(key).forEach(function(item){
       myDico2.set(item,'')
    })
  })
  var connectionKeys = []
  myDico2.forEach(function(value, key) {
    connectionKeys.push(key)
  })
  var data = responseJson.connections.map(e => connectionKeys.map(f => {
      return e[f] instanceof Array ? e[f].join(separator) : e[f];
  })); 
  data.unshift(connectionKeys);

  };
  //data = data.map(x => x.map(y => typeof y === 'undefined' || null ? "" : y));

  return data
}

编辑:这是输出需要的样子 (列顺序不重要) 元素数据

连接数据

Google sheet 有数据 https://docs.google.com/spreadsheets/d/1yO3gX61MroPrYL2l1YnfDxloa5naAX6HG2Q2f5ED_lY/edit?usp=sharing

尝试

let  Source =Json.Document(File.Contents("C:\Temp\kumu_json.json")),
Expanded=Table.FromRecords (Source[elements] ),
#"Added Index" = Table.AddIndexColumn(Expanded, "Index", 0, 1, Int64.Type),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Index"}, "Attribute", "Value"),
#"Combine items in list" = Table.TransformColumns(#"Unpivoted Other Columns",{{"Value", each try if Value.Is(_, type list ) then Text.Combine(_,", ") else _ otherwise _, type text}}),
#"Pivoted Column" = Table.Pivot(#"Combine items in list", List.Distinct(#"Combine items in list"[Attribute]), "Attribute", "Value"),
#"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Index"}),
#"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",List.Transform(Table.ColumnNames(#"Removed Columns"),each {_,type text}))
in  #"Changed Type"