📜  使用 jq 删除 JSON 属性 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:58.498000             🧑  作者: Mango

代码示例1
#!/bin/bash

if [ $# -lt 2 ]; then 
  echo "This script requires jq to be installed." 
  echo "It will delete the specified property (i.e., key and value) in the JSON file."
  echo "Two arguments required: key, and json file to modify, e.g."
  echo "" 
  echo "jdel Modality jq_test.json"
  echo ""
  echo "======================="
  exit 1 
else 
  key=$1
  file=$2
  jq 'del(."'"$key"'")' $file > tmp.$$.json && mv tmp.$$.json $file
fi