Page MenuHomePhabricator
Paste P6321

API response size difference when removing detail and detailHTML
ActivePublic

Authored by Lucas_Werkmeister_WMDE on Nov 15 2017, 5:35 PM.
json=$(
curl -G \
-d 'format=json' \
-d 'formatversion=2' \
-d 'action=wbcheckconstraints' \
-d 'id=Q64' \
https://www.wikidata.org/w/api.php
)
withDetail=$(
printf '%s' "$json" |
jq -c . |
wc -c
)
withoutDetail=$(
printf '%s' "$json" |
jq -c '
del(
.. |
objects |
select(has("constraint")) |
.constraint |
(.detail, .detailHTML)
)
' |
wc -c
)
awk \
-v "withDetail=$withDetail" \
-v "withoutDetail=$withoutDetail" \
'END {
removed = withDetail-withoutDetail
printf "%2.2f%%\n", 100 * removed / withDetail
}' < /dev/null