jq for cmd line and json

I recently came accross a new challenge where I needed to read the output of a particular json output from calling the commerce utility to force the loading of an index.

I was trying to resolve a problem where one of the search index core for the client was not getting updated after the indexprop utility gets called.

I created a script forceCoreProp.sh that with some modifications can be adapted to different clients. It reads the index from the AUTH servers, and it then calls the force replication cmd in the repeater using the specific version from the AUTH servers. The logic was simple but the challenge was on reading the output of the json output and getting the field related to the status of the job. I noticed what some collegues had done, but I wasn’t convinced that it was the best way to do it.

Did some digging and I found jq, a utility that is in most Linux system and can be used to easily nagivate a json.

To get the return code of the json provided by the index replication cmd all I had to do was RETURN_CODE=$(echo $INDEX_PROP_JSON | jq '.responseHeader.status')