Skip to content
This repository was archived by the owner on Nov 21, 2025. It is now read-only.

Commit 866b1ac

Browse files
committed
(#2) Found a way to use POSIX sed(1) after all.
The limitation here is that your JSON can't contain ASCII record separator characters.
1 parent 58f85ad commit 866b1ac

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
json.sh
22
=======
33

4-
Pure-shell [JSON](http://json.org/) parser.
5-
6-
`json.sh` requires GNU `sed`(1).
4+
Pure-POSIX-shell [JSON](http://json.org/) parser.
75

86
Example
97
-------

lib/json.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ json() {
4343
# The subtlety is that real newline characters are chomped so they
4444
# must be indirectly detected by checking for zero-length
4545
# characters, which is done as the character is emitted.
46-
sed -r "
47-
s/./&\\n/g
46+
sed "
47+
s/./&$(printf "\036")/g
4848
s/\\\\/\\\\\\\\/g
49-
" | _json
49+
" | tr "\036" "\n" | _json
5050

5151
# TODO Replace the original value of IFS. Be careful if it's unset.
5252

0 commit comments

Comments
 (0)