Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

delete JSON properties in place with jq

#!/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
 
PREVIOUS NEXT
Tagged: #delete #JSON #properties #place #jq
ADD COMMENT
Topic
Name
3+7 =