在Power BI中解析.json列

时间:2016-11-28 14:24:55

标签: json parsing powerbi

我想通过Power BI解析.json列。我直接从服务器导入数据,并在数据中包含.json列以及其他列。有没有办法解析这个json列?

示例:

       Key      IDNumber    Module      JsonResult  
       012      200         Dine        {"CategoryType":"dining","City":"mumbai"',"Location":"all"} 
       97       303         Fly         {"JourneyType":"Return","Origin":"Mumbai (BOM)","Destination":"Chennai (MAA)","DepartureDate":"20-Oct-2016","ReturnDate":"21-Oct-2016","FlyAdult":"1","FlyChildren":"0","FlyInfant":"0","PromoCode":""} 
       276      6303        Stay        {"Destination":"Clarion Chennai","CheckInDate":"14-Oct-2016","CheckOutDate":"15-Oct-2016","Rooms":"1","NoOfPax":"2","NoOfAdult":"2","NoOfChildren":"0"}

我希望保留其他列,并获得简化的解析列。

4 个答案:

答案 0 :(得分:26)

有一种更简单的方法,在您想要作为json读取的列的查询编辑器中:

  • 右键单击列
  • 选择转换> JSON

然后该列成为一个记录,您可以使用右上角的按钮在json的每个属性中拆分。

split columns

答案 1 :(得分:10)

使用像这样的Json.Document函数

let
    ...
    your_table=imported_the_data_directly_from_the_server,
    json=Table.AddColumn(your_table, "NewColName", each Json.Document([JsonResult]))
in
    json

然后使用Table.ExpandRecordColumn

将记录扩展到表格

或点击此按钮

enter image description here

答案 2 :(得分:0)

使用 Json.Document() 函数将字符串转换为Json数据。

let
    Source = Json.Document(Json.Document(Web.Contents("http://localhost:18091/pools/default/buckets/Aggregation/docs/AvgSumAssuredByProduct"))[json]),
    #"Converted to Table" = Record.ToTable(Source),
    #"Filtered Rows" = Table.SelectRows(#"Converted to Table", each not Text.Contains([Name], "type_")),
    #"Renamed Columns" = Table.RenameColumns(#"Filtered Rows",{{"Name", "AvgSumAssuredByProduct"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Value", type number}})
in
    #"Changed Type"

答案 3 :(得分:-2)

import json
from urllib import urlopen
import string
from UserList import *
l=[]
j=[]
d_base=urlopen('https://api.thingspeak.com/channels/193888/fields/1.json?results=1')
data = json.load(d_base)
for k in data['feeds']:
        name = k['entry_id']
        value = k['field1']
        l.append(name)
        j.append(value)

print l[0]
print j[0]

**这个python代码可能对你有用** ** 270   1035 **

相关问题