32 lines
817 B
Bash
32 lines
817 B
Bash
##@cooked comments # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
|
## gestion de contenu au format json
|
|
##@cooked nocomments
|
|
##@require base
|
|
uprovide json
|
|
urequire base
|
|
|
|
function json_filter() {
|
|
# traiter un flux json pour que chaque valeur soit sur une ligne séparée,
|
|
# facilitant le traitement par un script bash
|
|
awk '{
|
|
gsub(/}\][ ]*$/, "\n&")
|
|
gsub(/},[ ]*$/, "\n&")
|
|
gsub(/[][{]/, "&\n")
|
|
gsub(/,[ ]*"/, ",\n\"")
|
|
gsub(/"}/, "\",\n}")
|
|
print
|
|
}'
|
|
}
|
|
|
|
JSONFUNCS='
|
|
function json_get(line) {
|
|
if (!line) line = $0
|
|
match(line, /^[^"]*"[^"]*":[ ]*"?/); line = substr(line, RSTART + RLENGTH)
|
|
match(line, /"?[ ]*,?[ ]*$/); line = substr(line, 1, RSTART - 1)
|
|
return line
|
|
}
|
|
'
|
|
function awkjson() {
|
|
json_filter | awkrun -f "$JSONFUNCS" "$@"
|
|
}
|