mirror of
https://github.com/rwxrob/dot
synced 2024-11-18 15:25:52 +00:00
26 lines
606 B
Plaintext
26 lines
606 B
Plaintext
|
#!/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}"
|