标签: google-refine

在Google Refine中解析JSON

我正在尝试使用Google Refine从Data Science Toolkit coordinates2politics API中提取特定元素.

这是样本单元#1:

[{"politics":[
 {"type":"admin2","friendly_type":"country","code":"usa","name":"United States"},
 {"type":"admin6","friendly_type":"county","code":"55_025","name":"Dane"},
 {"type":"constituency","friendly_type":"constituency","code":"55_02","name":"Second district, WI"},
 {"type":"admin5","friendly_type":"city","code":"55_48000","name":"Madison"},
 {"type":"admin5","friendly_type":"city","code":"55_53675","name":"Monona"},
 {"type":"admin4","friendly_type":"state","code":"us55","name":"Wisconsin"},
 {"type":"neighborhood","friendly_type":"neighborhood","code":"Eastmorland|Madison|WI","name":"Eastmorland"}
 ],"location":{"longitude":"-89.3259404","latitude":"43.0859191"}}]
Run Code Online (Sandbox Code Playgroud)

我使用这个GREL语法添加了一个基于此专栏的专栏来推出该县,Dane:

value.parseJson()[0]["politics"][1]["name"]
Run Code Online (Sandbox Code Playgroud)

但是当我进入Sample Cell#2时,语法不再有效,因为JSON结果有点不同:

[{"politics":[
 {"type":"admin2","friendly_type":"country","code":"usa","name":"United States"},
 {"type":"constituency","friendly_type":"constituency","code":"55_05","name":"Fifth district, WI"},
 {"type":"admin4","friendly_type":"state","code":"us55","name":"Wisconsin"},
 {"type":"admin6","friendly_type":"county","code":"55_079","name":"Milwaukee"},
 {"type":"admin5","friendly_type":"city","code":"55_84675","name":"Wauwatosa"},
 {"type":"constituency","friendly_type":"constituency","code":"55_04","name":"Fourth district, WI"}
 ],"location":{"longitude":"-88.0075875","latitude":"43.0494572"}}]
Run Code Online (Sandbox Code Playgroud)

有没有办法对JSON或短语我的语法进行排序,以便我可以在任何一种情况下找到该县?

更新

这是神奇的GREL,它允许我按名称在JSON字符串中查找元素,而不仅仅是位置:

filter(value.parseJson()[0]["politics"], item, item["type"]=="admin6")[0]["name"]
Run Code Online (Sandbox Code Playgroud)

parsing json google-refine

7
推荐指数
1
解决办法
4114
查看次数

Openrefine列中的渐进数字

是否可以使用GREL生成"计数器",列中的渐进数字?

例如,我想添加value该数字来为每条记录生成一个标识符.

google-refine openrefine

4
推荐指数
1
解决办法
199
查看次数

如何在 GREL 中使用 GoogleRefine 或 OpenRefine 生成随机数?

我想在 GREL 中生成随机数。有没有办法做到这一点?我想使用 GREL 短语,例如:

" http://example.org/id/ " + 随机 + ".html"

random google-refine openrefine grel

0
推荐指数
1
解决办法
414
查看次数

标签 统计

google-refine ×3

openrefine ×2

grel ×1

json ×1

parsing ×1

random ×1