News for hackers. Stuff that matters.
Re:Jqjq: Jq Implementation of Jq by olooney on Friday November 25, 2022 @09:17AM (#33742573)
Has this happened to you? You're logged into a remote server and trying to read a config file or log file. The problem is its in a minified JSON format and looks like a solid wall of noise when you try to use `less`. You reach for your go-to JSON swiss army knife `jq` but it's not installed! You don't have root access to install it via `apt-get` so you need a script you can run locally. Just copy the `jqjq` and `jqjq.jq` files to your local directory, and now you can access the full power of jq just by running `./jqjq`. Problem solved! And the best part is that the only dependency is `jq`, which should be installed pretty much everywhere.
Re:Jqjq: Jq Implementation of Jq by rpadovani on Friday November 25, 2022 @09:32AM (#33742683)
> And the best part is that the only dependency is `jq`, which should be installed pretty much everywhere.

I am confused by this sentence. Wasn't the entire premise that js is NOT installed?

Re:Jqjq: Jq Implementation of Jq by jjice on Friday November 25, 2022 @09:37AM (#33742728)
I believe that that was the joke
Re:Jqjq: Jq Implementation of Jq by omaranto on Friday November 25, 2022 @09:55AM (#33742905)
You understood the joke, you just didn't find it funny.
Re:Jqjq: Jq Implementation of Jq by foob on Friday November 25, 2022 @09:44AM (#33742796)
Jokes aside, this is a actually a pretty common scenario for some people, and I wrote a tool called Exodus to solve it [1]. Exodus makes it trivial to relocate Linux binaries like jq from your local machine [1]. You can simply run

  exodus jq | ssh my-server
locally, and then immediately have access to jq on the server. I personally find it very useful when working with servers or containers that have limited package repositories or where I don't have root access.

[1] - https://github.com/intoli/exodus

Re:Jqjq: Jq Implementation of Jq by fwsgonzo on Friday November 25, 2022 @10:26AM (#33743197)
That is very cool, and it's going to help me alot on old RHELs I think. Looks like it was actually very complicated to make!
Re:Jqjq: Jq Implementation of Jq by andai on Friday November 25, 2022 @10:10AM (#33743032)
>Exodus handles bundling all of the binary's dependencies, compiling a statically linked wrapper for the executable that invokes the relocated linker directly, and installing the bundle in ~/.exodus/ on the remote machine.

That's really neat.

Re:Jqjq: Jq Implementation of Jq by efrecon on Friday November 25, 2022 @09:56AM (#33742912)
Ooh. Thank you for Exodus! It is fantastic!
Re:Jqjq: Jq Implementation of Jq by metadat on Friday November 25, 2022 @11:41AM (#33744124)
Discussed 11 months ago:

Exodus – relocation of Linux binaries–and all of their deps–without containers

https://news.ycombinator.com/item?id=29446297

(307 points, 65 comments)

Re:Jqjq: Jq Implementation of Jq by kasbah on Friday November 25, 2022 @10:13AM (#33743063)
In all seriousness Python's json.tool is a great option here.

    cat big.json | python3 -m json.tool
or

    python3 -m json.tool big.json
Re:Jqjq: Jq Implementation of Jq by jwilk on Friday November 25, 2022 @02:32PM (#33745952)
There's also json_pp(1), provided by Perl.
Re:Jqjq: Jq Implementation of Jq by ilyt on Friday November 25, 2022 @10:24AM (#33743175)
Joking aside

    ssh badly-managed-server cat file | jq .
Problem solved !

I actually made a wrapper that just guesses (based on which parser returns error basically) type of serializing and then displays it nicely.

Re:Jqjq: Jq Implementation of Jq by eurasiantiger on Friday November 25, 2022 @05:38PM (#33747604)
Thanks for this. The pattern is useful for much more and sure beats pushing ad-hoc 3rd-party-relinked binaries to production containers.

Then again, why not scp the file to local? Bandwidth usage isn’t good for the environment.

Re:Jqjq: Jq Implementation of Jq by TheReveller on Friday November 25, 2022 @09:24PM (#33749240)
Why stop at one file, is it possible to locally mount a remote folder over ssh?
Re:Jqjq: Jq Implementation of Jq by Too on Saturday November 26, 2022 @01:07AM (#33750402)
Yep, it's called sshfs, very easy to use.
Re:Jqjq: Jq Implementation of Jq by ilyt on Saturday November 26, 2022 @03:57PM (#33756652)
here is function I use

    sshmount () {
     SSHFS_SERVER_DIR='/home/user' 
     if [ "z$1" = "z" ]
     then
      echo "specify server [server_dir]"
      return
     fi
     SSHFS_SERVER=$1 
     if [ "z$2" != "z" ]
     then
      SSHFS_SERVER_DIR=$2 
     fi
     SSHFS_TARGET_DIR="/home/user/mnt/$SSHFS_SERVER" 
     echo "Mounting $SSHFS_SERVER:$SSHFS_SERVER_DIR into $SSHFS_TARGET_DIR"
     mkdir -p $SSHFS_TARGET_DIR
     sshfs -o idmap=user -o allow_other -o kernel_cache $SSHFS_SERVER:$SSHFS_SERVER_DIR $SSHFS_TARGET_DIR && cd $SSHFS_TARGET_DIR
    }
    
    sshmount servername
will mount server's home in directory /home/user/mnt/servername, second parameter changes the server dir to specified one
Re:Jqjq: Jq Implementation of Jq by cerved on Friday November 25, 2022 @11:27AM (#33743925)
You can use cut, tr and sed

https://stackoverflow.com/a/70614580/1507124

it's not full pretty, rather just newline delimits arrays. Incidentally, it's much faster than jq. Probably wouldn't use it for anything serious

Re:Jqjq: Jq Implementation of Jq by blackhaz on Friday November 25, 2022 @01:33PM (#33745365)
Just out of curiosity, why would anyone want to store a config file in a minified JSON format?
Re:Jqjq: Jq Implementation of Jq by yjftsjthsd-h on Friday November 25, 2022 @02:20PM (#33745850)
Probably computer generated and defaulted to compact output.
Re:Jqjq: Jq Implementation of Jq by yjftsjthsd-h on Friday November 25, 2022 @02:19PM (#33745839)
Bravo; I got most of the way through before catching the joke:)