PERL : anyone have a suggestion for a (pdf) book about JSON parsing?
GeneralThis forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Arch Linux && OpenBSD 7.4 && Pop!_OS && Kali && Qubes-Os
Posts: 824
Rep:
PERL : anyone have a suggestion for a (pdf) book about JSON parsing?
hello ladies and gents.
anyone who knows a good book of JSON parsing in perl, post here so i can do some
i have done quick google searches but i am not sure what modules i should use.
actually, i found one book just when i were writing this post : Practical perl tools - a little place for your stuff. <-- anyone heard about that one?
tia.
EDIT: i think ill be using "JSON::MaybeXS", is that "good one" ?
Last edited by //////; 02-18-2021 at 01:56 PM.
Reason: did some searching.
Really cannot comment on this as I never used it. Actually, I never parsed JSON in Perl proper. CLI tools like jq, json_pp, json_xs, etc. are usually enough for my needs. E.g. when trying to tackle the problem from this thread, I wrote this:
Code:
#!/bin/bash
text='[[{"Key":"PORT",context:"5436"},{"Key":"HOST",context:"prod"},{"Key":"ADD",context:"location"}]]'
echo === sed+jq ===
sed 's/\<context\>/"&"/g' <<<"$text" | jq -c '.[][]|select(.Key=="HOST")'
# Remove the outer array with sed. Another possibility: jgrep -n
echo === sed+jgrep ===
sed 's/^.\(.*\).$/\1/;s/\<context\>/"&"/g' <<<"$text" | jgrep -c 'Key="HOST"'
# jt is similar to jshon
echo === sed+jt+grep ===
sed 's/\<context\>/"&"/g' <<<"$text" | jt [ Key % ] context % | grep -w ^HOST
# Remove the outer array with jt
echo === sed+jt+mlr ===
sed 's/\<context\>/"&"/g' <<<"$text" | jt % | mlr --json filter '$Key=="HOST"'
echo === pyjson5+jq ===
pyjson5 --as-json -c "$text" | jq -c '..|select(.Key?=="HOST")'
echo === json_pp+json_xs ===
json_pp -json_opt allow_barekey <<<"$text" |
json_xs -e '($_) = grep { $_->{Key} eq "HOST" } @{$_->[0]}'
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.