Skip to content

Commit

Permalink
to_json.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
bwhitehead0 committed May 22, 2024
1 parent b23afc7 commit edcb1d5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions assets/to_json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# Read key-value pairs from pipeline
while IFS=':' read -r key value; do
# Remove leading/trailing whitespace from key and value
key=$(echo "$key" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
value=$(echo "$value" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')

# Add key-value pair to JSON object
json+="\"$key\":\"$value\","
done

# Remove trailing comma from JSON object
json="${json%,}"

# Print the JSON object
echo "{$json}"

0 comments on commit edcb1d5

Please sign in to comment.