jq headache
Have this structure of JSON:
(
[0] => stdClass Object
(
[create_user] => Array
(
[0] => stdClass Object
(
[time] => 2022-10-01_12:43:05
[level] => success
[message] => Username created: xbnitapwr
)
)
)
[1] => stdClass Object
(
[create_user] => Array
(
[0] => stdClass Object
(
[time] => 2022-10-01_12:43:05
[level] => success
[message] => User modified: xbnitapwr
)
)
)
)
I need to make it like this:
(
[0] => stdClass Object
(
[create_user] => Array
(
[0] => stdClass Object
(
[time] => 2022-10-01_12:43:05
[level] => success
[message] => Username created: xbnitapwr
)
[1] => stdClass Object
(
[time] => 2022-10-01_12:43:05
[level] => success
[message] => User modified: xbnitapwr
)
)
)
)
TL;DR: I need to group elements by create_user key. And this is in bash env with jq. Any suggestions?
Comments
idk, just python, is already installed on most linux distros.
Free NAT KVM | Free NAT LXC | Bobr
ITS WEDNESDAY MY DUDES
I know jq well.
jq deals with JSON, not PHP print_r.
Hence, you need to write your snippets in actual JSON.
HostBrr aff best VPS; VirmAche aff worst VPS.
Unable to push-up due to shoulder injury 😣
I've long since concluded jq is witchcraft so usually do same as Neoon. Hopefully someone else can help, cause def seems like something that is doable with bash & jq
one advise about
jq "some filter" | jq "other filter" | jq "the clit"
until you get it.
as for env vars you'll need to bash script and test first.
btw, are you sure inputs are vaild jsons.
I just presented output from php . Json is really valid. Have some mumbo jumbo in bash wich send info to php backend api. I guess it is more doable in php side...
I'm glad I'm not the only person who thinks jq is witchcraft.
Get the best deal on your next VPS or Shared/Reseller hosting from RacknerdTracker.com - The original aff garden.
Ou, just start using some awk magic with more advanced syntax. I can spend 8 hours straight mangling and searching for awk goodness. I guess depends on level of masochizm - you enjoy the process.
Ok... Trying to convert bash script into python. Immediately faced the fact how python is disgusting for me. Any suggestions how to solve this?
Result of this madness is:
This is URL: ['url.domain.tld']
I assume this
args.url
is a list object. Why the surounding [' '] , I need bare string.NVM, resolved with this:
url = args.url[0]
But for me this is insane... I need to look for another tool.
Is PHP an option? You said it was easy for you in PHP.
In jq, I think you'd want to construct the main list using the recursive descent filter (..).
Yes, PHP I understand and syntax is human readable. Thank you for suggestion.