jqを含むJSON、すべての値を*に変更する

jqを含むJSON、すべての値を*に変更する

JSONファイルのすべての値を*に置き換えてから、出力を新しいJSONファイルに返す必要があります。

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "Global": {
    "Version": "1.0.0",
    "Environment": {
      "Long": "Local",
      "Short": "loc"
    },
    "ActiveDirectory": {
      "Role": {
        "User": "user",
        "Manager": "manager",
        "Admin": "admin"
      }
    },
    "Jwt": {
      "Authority": "http://localost:8089/auth/reals/master",
      "Audience": "pneumanet-client",
      "AuthorizationUrl": "http://localost:8089/auth/reals/master/protocol/openid-connect/auth",
      "TokenUrl": "http://localost:8089/auth/reals/master/protocol/openid-connect/token",
      "Real": "master"
    }
  }
}

「Default」:「Information」のような値を持つすべてのキーを見ることができるように、「Information」を*に変更したいと思います。これはすべてのキー値フィールドに適用する必要があります。私が理解できないので、これはjqで可能ですか?ありがとうございます。

ベストアンサー1

..1つの可能なアプローチは、再帰降下()を使用して値を持つノードを選択し"Information"て更新することです。

$ jq '(.. | select(. == "Information")) |= "*"' file.json
{
  "Logging": {
    "LogLevel": {
      "Default": "*",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "*"
    }
  },
  "Global": {
    "Version": "1.0.0",
    "Environment": {
      "Long": "Local",
      "Short": "loc"
    },
    "ActiveDirectory": {
      "Role": {
        "User": "user",
        "Manager": "manager",
        "Admin": "admin"
      }
    },
    "Jwt": {
      "Authority": "http://localost:8089/auth/reals/master",
      "Audience": "pneumanet-client",
      "AuthorizationUrl": "http://localost:8089/auth/reals/master/protocol/openid-connect/auth",
      "TokenUrl": "http://localost:8089/auth/reals/master/protocol/openid-connect/token",
      "Real": "master"
    }
  }
}

おすすめ記事