Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 584

How to execute multi attribute selection jq command on a external json file from windows cmder

$
0
0

I'm attempting to use windows cmder to execute jq commands for command-line JSON processor to transform and output existing JSON files I have saved.

Given the the sample json

[  {"firstName": "Doug","accountNumber": "123456","language": "en_US","brand": "Tide","country": "US","branch": "MIA","city": "Miami","state": "FL","zipCode": "33133"  }]

While I am able to output the files for simple filter output such the following:

cat sample.json | jq .[] --color-output

or

jq .[] sample.json --color-output

or a filter on a single attribute like country (any nested items within whenever present with dot notation)

jq .[].country sample.json --color-output

Unfortunately, I am unable to perform any of the more complex actions such as extracting specific attributes or filtering for specific using online resources like jqplay which allow me to use

.[] | {accountNumber:.accountNumber, brand:.brand, city:.city, state:.state}

When I try to perform this same type of command that worked on jqplay within cmder to transform the sample json data to display with only certain fields, I receive the following error.

jq '.[] | {accountNumber:.accountNumber, brand:.brand, city:.city, state:.state}' sample.json

error message: The filename, directory name, or volume label syntax is incorrect.

I looked through a few jq documentation resources such as the jq manual and jq cheatsheet and while I saw examples of how it suggest extracting attributes, I have not been able to get such filtering/transforming to work when referring to any of my sample JSON files like this but the files read in fine for the single attribute selection example I illustrated earlier. I imagine if I've written incorrect syntax for cmder reading local or remote JSON files it will be easy for someone here to identify and help correct. I really want to be able to this on windows cmder like most things and not powershell or anything like that.


Viewing all articles
Browse latest Browse all 584

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>