用 jq 改变 json 对象

Change json object with jq

如何使用 jq 更新 json 中的服务器对象?

"tags": [],
  "servers": [],
  "components": {
    "securitySchemes": {
      "cookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "store",
        "description": "Store API"
      }
    },

我需要这样的服务器:

      "servers": [
    {
      "url": "http://localhost:5000",
      "description": "Localhost server"
    }
  ],
echo '{"tags": [],
  "servers": [],
  "components": {
    "securitySchemes": {
      "cookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "store",
        "description": "Store API"
      }
    }
}}' | jq '.servers = [{url:"http://localhost:5000", description: "Localhost server"}]'

或者,对于固定的 json 文件(添加缺失的 }):

jq '.servers = [{url:"http://localhost:5000", description: "Localhost server"}]' file.json