惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
V
V2EX
博客园_首页
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Recent Announcements
Recent Announcements
博客园 - 司徒正美
Microsoft Security Blog
Microsoft Security Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Latest news
Latest news
Vercel News
Vercel News
The Register - Security
The Register - Security
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
N
Netflix TechBlog - Medium
WordPress大学
WordPress大学
小众软件
小众软件
L
Lohrmann on Cybersecurity
GbyAI
GbyAI
P
Privacy & Cybersecurity Law Blog
T
Tor Project blog
AWS News Blog
AWS News Blog
美团技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
K
Kaspersky official blog
B
Blog RSS Feed
G
Google Developers Blog
量子位
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
Scott Helme
Scott Helme
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
I
Intezer
雷峰网
雷峰网
Martin Fowler
Martin Fowler
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Blog — PlanetScale
Blog — PlanetScale
IT之家
IT之家
F
Full Disclosure
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 【当耐特】
The Hacker News
The Hacker News
U
Unit 42
S
SegmentFault 最新的问题
I
InfoQ
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
宝玉的分享
宝玉的分享
罗磊的独立博客
Spread Privacy
Spread Privacy
C
CERT Recently Published Vulnerability Notes

夜行人

回家路上 第一期的直播演示项目 震动检测器 正能量 在线参观CodeLab Neverland 发布 CodeLab Adapter 3.3.1 DynamicTable 之 纸糊方向盘 CodeLab DynamicTable: 一个可实施的技术方案 CodeLab Insight 发布 Alpha 版 情人节 Home Assistant 周报 && IoT 周报 (02) Joplin: 关注隐私的 Evernote 开源替代软件 浏览器的未来与 Web 传感器 Home Assistant 周报 && IoT 周报 (01) 百宝箱(01) 论自由 介绍 WebThings Home Assistant 周报 && iot 周报 (00) 百宝箱(00) 毛姆读书心得 传世之作 周末徒步 CodeLab Adapter ❤️ Jupyter/Python 航班 躲雨 夏令营途中 [译]思想--作为一种技术 The future of coding 美国之行 三门问题的程序模拟 从Python转向Pharo https://blog.just4fun.site/post/iot/iot-open-source-projects/ Python异步编程笔记 https://blog.just4fun.site/post/iot/iot-open-source-hardware-community/ 万物积木化开发者社区 CodeLab ❤️ Blender Scratch3技术分析之云变量 API(第7篇) [译]对管道(Pipes)的偏爱 [译]提出正确的问题比得到正确答案更重要 蓝牙设备与Scratch3.0 创建你的第一个Scratch3.0 Extension Scratch3技术分析之项目内部数据(第6篇) Scratch3技术分析之社区 API(第5篇) Scratch3技术分析之User API(第4篇) Scratch3技术分析之项目主页API(第3篇) Scratch3技术分析之静态资源API(第2篇) Scratch3.0、micro:bit与Windows7 https://blog.just4fun.site/post/iot/zerynth-vs-micropython/ 核聚变、方所与半宅空间 可视化编程为何是个糟糕的主意 codelab.club周末聚会 关于codelab.club '下一件大事'是一个房间 Hungry Robot - Eat everything 编程作为一种思考方式 今日简史 史蒂夫·乔布斯传 罗素自选文集 https://blog.just4fun.site/post/edx/tianjin-scratch-ai/ https://blog.just4fun.site/post/edx/richie-cms-openedx/ 徒步武功山 WebUSB与micro:bit 积木化编程与3D场景 夜宿武功山顶 scratch3-adapter接入优必选Alpha系列机器人 https://blog.just4fun.site/post/edx/video-migration-note/ scratch3-adapter重构笔记 https://blog.just4fun.site/post/edx/edx-community-members/ 两种硬件编程风格的比较 使用micro:bit自制PPT翻页笔 柏拉图对话集 scratch3.0 + micro:bit 七月电影放映计划 非营利组织的管理 Screenly--用树莓派让任何屏幕变为可编程的数字标牌 以最佳实践开始你的Django项目 micro:bit与事件驱动 为Scratch3.0设计的插件系统(上篇) OCR应用一例 近两年读过的一些好书 blockly开发之使用python驱动浏览器中的turtle(2) 牛顿新传 文学理论入门 逻辑的引擎 人生的意义 blockly开发之生成并运行js代码(1) blockly开发之hello world(0) micro:bit使用笔记 神器之Termux https://blog.just4fun.site/post/iot/micropython-notes/ Cozmo what is this Scratch的前世今生 下段旅程 我行在远方 爆裂 途中杂记 https://blog.just4fun.site/post/edx/open-edx-startup/ cozmo系列之入门 - 有性格且可编程的机器人 PaperWeekly开发笔记 创业二三事
命令行神器之jq
2015-10-29 · via 夜行人

神器有很多种,有一种是你一旦试用,就无法想象遇到它之前都是怎么过来的

jq属于这种

#是什么

jq is a lightweight and flexible command-line JSON processor

jq是一款命令行工具,专门用来处理json文件,与所有优秀的命令行工具一样,短小精悍,通过管道他们相互协作,组合出惊人的效果

jq的使用习惯和sed/grep相似

#安装

  • mac: brew install jq
  • ubuntu: sudo apt-get install jq

#使用 cat account.json

1
{"username": "wwj", "bio": null, "requires_parental_consent": true, "name": "wwj", "country": null, "is_active": true, "profile_image": {"image_url_full": "http://example.com/static/images/default-theme/default-profile_500.de2c6854f1eb.png", "image_url_large": "http://example.com/static/images/default-theme/default-profile_120.33ad4f755071.png", "image_url_medium": "http://example.com/static/images/default-theme/default-profile_50.5fb006f96a15.png", "image_url_small": "http://example.com/static/images/default-theme/default-profile_30.ae6a9ca9b390.png", "has_image": false}, "year_of_birth": null, "level_of_education": null, "goals": null, "language_proficiencies": [], "gender": null, "mailing_address": null, "email": "wwj@example.com", "date_joined": "2015-05-13T09:42:45Z"}

###原文输出(格式化json) cat ./account.json|jq '.'

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
  "username": "wwj",
  "bio": null,
  "requires_parental_consent": true,
  "name": "wwj",
  "country": null,
  "is_active": true,
  "profile_image": {
    "image_url_full": "http://example.com/static/images/default-theme/default-profile_500.de2c6854f1eb.png",
    "image_url_large": "http://example.com/static/images/default-theme/default-profile_120.33ad4f755071.png",
    "image_url_medium": "http://example.com/static/images/default-theme/default-profile_50.5fb006f96a15.png",
    "image_url_small": "http://example.com/static/images/default-theme/default-profile_30.ae6a9ca9b390.png",
    "has_image": false
  },
  "year_of_birth": null,
  "level_of_education": null,
  "goals": null,
  "language_proficiencies": [],
  "gender": null,
  "mailing_address": null,
  "email": "wwj@example.com",
  "date_joined": "2015-05-13T09:42:45Z"
}

###过滤 cat ./account.json|jq '.profile_image'

1
2
3
4
5
6
7
{
  "image_url_full": "http://example.com/static/images/default-theme/default-profile_500.de2c6854f1eb.png",
  "image_url_large": "http://example.com/static/images/default-theme/default-profile_120.33ad4f755071.png",
  "image_url_medium": "http://example.com/static/images/default-theme/default-profile_50.5fb006f96a15.png",
  "image_url_small": "http://example.com/static/images/default-theme/default-profile_30.ae6a9ca9b390.png",
  "has_image": false
}

如果key不存在则返回null

cat ./account.json|jq '.testname' 返回null

###支持嵌套 cat ./account.json|jq '.profile_image.image_url_full'

"http://example.com/static/images/default-theme/default-profile_500.de2c6854f1eb.png"

###语法检查 cat test.json

1
2
3
4
5
{
    "a":"a",
    ddd"b":"b",
    "c":"c"
}

cat test.json | jq '.'返回parse error: Invalid numeric literal at line 3, column 8

##在线体验 jqplay.org

##上手 Tutorial

##文档 manual

##进阶 Cookbook

##在edx-platform中使用 /edx/app/edxapp/*.*.json用于覆盖aws.py和devstack.py里的配置参数,为用户配置edx提供了便利,但是由于缺乏语法检查一个小失误(诸如漏了逗号,漏了引号),就会造成edx启动失败,而且错误信息几乎无法定位。

有了jq,可以方便地检查语法以及查看参数

如果我们把jq当做处理json数据的sed,还可以方便用来写配置edx的脚本

###我的实践

文章作者 种瓜

上次更新 2015-10-29