使用jq批量更新本地json文件

时间:2018-05-06 10:46:44

标签: json jq

我的本​​地mac PC中有一个JSON文件名var express = require("express"); var app = express(); var test = require('./test'); var test_ob = new test(); app.get('/testAPI',test_ob.b); 我的JSON文件具有这种结构

emoji.json

我希望删除一些不需要的值,以便文件变得像打击一样。 我想在我的电脑中以JSON格式保存这个文件

[
{
    "name": "COPYRIGHT SIGN",
    "unified": "00A9-FE0F",
    "non_qualified": "00A9",
    "docomo": "E731",
    "au": "E558",
    "softbank": "E24E",
    "google": "FEB29",
    "image": "00a9-fe0f.png",
    "sheet_x": 0,
    "sheet_y": 12,
    "s": "copyright",
    "short_names": [
        "copyright"
    ],
    "text": null,
    "texts": null,
    "c": "Symbols",
    "o": 128,
    "added_in": "1.1",
    "has_img_twitter": false,
    "has_img_emojione": false,
    "has_img_messenger": false
},
{
    "name": "REGISTERED SIGN",
    "unified": "00AE-FE0F",
    "non_qualified": "00AE",
    "docomo": "E736",
    "au": "E559",
    "softbank": "E24F",
    "google": "FEB2D",
    "image": "00ae-fe0f.png",
    "sheet_x": 0,
    "sheet_y": 13,
    "s": "registered",
    "short_names": [
        "registered"
    ],
    "text": null,
    "texts": null,
    "c": "Symbols",
    "o": 129,
    "added_in": "1.1",
    "has_img_twitter": false,
    "has_img_emojione": false,
    "has_img_messenger": false
}
...
]

我知道JQ可以这样做,我检查文档和https://jqplay.org/ 我测试并发现[ { "s": "copyright", "c": "Symbols", "o": 128 }, { "s": "registered", "c": "Symbols", "o": 129 } ] 可以做到这一点,但我找到了如何输入文件和导出文件

1 个答案:

答案 0 :(得分:1)

jq + mv方法:

jq 'map({s, c, o})' emoji.json > tmp_json && mv tmp_json emoji.json