mirror of https://github.com/rwxrob/dot
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
606 B
Bash
26 lines
606 B
Bash
#!/usr/bin/env bash
|
|
|
|
# note, unicode is passed as is (as it should be, imho)
|
|
# and forward slashes are not unnecessarily escaped
|
|
jsonesc () {
|
|
local q="$1"
|
|
q=${q//$'\\'/\\\\} # back slash (must be first)
|
|
q=${q//$'\"'/'\"'} # double quote
|
|
#q=${q//$'/'/'//'} # forward slash (but just no)
|
|
q=${q/$'\b'/'\b'} # backspace
|
|
q=${q//$'\f'/'\f'} # form feed
|
|
q=${q//$'\n'/'\n'} # line feed
|
|
q=${q//$'\r'/'\r'} # carriage return
|
|
q=${q/$'\t'/'\t'} # tab
|
|
printf '%s' $q
|
|
}
|
|
|
|
IFS=
|
|
read line
|
|
buf=$line
|
|
while IFS= read line; do
|
|
buf="${buf}"$'\n'"${line}"
|
|
done
|
|
|
|
jsonesc "${buf}"
|