Jq: Error putting multiple value of array on a single line?

Created on 9 Jan 2020  Â·  2Comments  Â·  Source: stedolan/jq

Describe the bug
I want read some attribute value from a video file into csv, but multi value in array will get error.

To Reproduce
mediainfo -f --Output=JSON higkoo.flv | jq -r '[."media"."@ref", ."media"."track"[] | select(."@type"=="General")."FileExtension"] | @csv'

jq: error (at :72): Cannot index string with string "@type"

mediainfo -f --Output=JSON higkoo.flv | jq -r '[."media"."@ref"], [."media"."track"[] | select(."@type"=="General")."FileExtension"] | @csv'

"higkoo.flv"
"flv"

Exec success, but value do not in One Line. Need One file attributes in One Line.
Then this script will read many many files, into csv to dispaly. Expected:

"higkoo.flv","flv"

Source String to Test:

{
"media": {
"@ref": "higkoo.flv",
"track": [{
"@type": "General","VideoCount": "1","AudioCount": "1",
"FileExtension": "flv","Format": "Flash Video",
"FileSize": "739869","Duration": "2.233",
"OverallBitRate": "2650673","FrameRate": "30.000","FrameCount": "67",
"File_Modified_Date": "UTC 2016-07-12 19:01:52",
"File_Modified_Date_Local": "2016-07-13 03:01:52",
"Encoded_Application": "Lavf56.40.101"
},{
"@type": "Video","Format": "AVC","Format_Profile": "Main",
"Format_Level": "3.1","Format_Settings_CABAC": "Yes",
"Format_Settings_RefFrames": "4","CodecID": "7",
"Duration": "2.233","BitRate": "2500000",
"Width": "1280","Height": "720","Sampled_Width": "1280",
"Sampled_Height": "720","PixelAspectRatio": "1.000",
"DisplayAspectRatio": "1.778","FrameRate_Mode": "CFR",
"FrameRate": "30.000","FrameCount": "67","ColorSpace": "YUV",
"ChromaSubsampling": "4:2:0","BitDepth": "8",
"ScanType": "Progressive","Delay": "0.000","StreamSize": "697812",
"Encoded_Library": "x264 - core 142","Encoded_Library_Name": "x264",
"Encoded_Library_Version": "core 142"
},{
"@type": "Audio","Format": "AAC",
"Format_AdditionalFeatures": "LC",
"CodecID": "10-2","Duration": "2.229",
"BitRate": "156250","Channels": "2",
"ChannelPositions": "Front: L R","ChannelLayout": "L R",
"SamplesPerFrame": "1024","SamplingRate": "44100",
"SamplingCount": "98299","FrameRate": "43.066",
"Compression_Mode": "Lossy","Delay": "0.000",
"Delay_Source": "Container","StreamSize": "43535",
"StreamSize_Proportion": "0.05884"
}]} }

Expected

Victory.Korea.avi,avi,67453106,206.76,720,480,1.333,25,2373150,XviD,MEncoder,2,MPEG
Audio,224000

Environment

  • macOS Catalina 10.15.2

    • MediaInfoLib - v19.09

  • jq-1.6

Additional
I want output multi values when use jq one time, please tell me howto.
Many thank.

support

Most helpful comment

mediainfo -f --Output=JSON higkoo.flv | jq '[."media"."@ref",."media"."@ref"]'

[
"higkoo.flv",
"higkoo.flv"
]

mediainfo -f --Output=JSON higkoo.flv | jq '[."media"."track"[] | select(."@type"=="General")."FileExtension"],[."media"."track"[] | select(."@type"=="General")."FileExtension"]'

[
"flv"
]
[
"flv"
]

mediainfo -f --Output=JSON higkoo.flv | jq '[."media"."track"[] | select(."@type"=="General")."FileExtension" , ."media"."track"[] | select(."@type"=="General")."FileExtension"]'

jq: error (at :65): Cannot index string with string "@type"

Expected

[
"flv",
"flv"
]

Need some value into a array then use "| @csv" output a csv file.

All 2 comments

mediainfo -f --Output=JSON higkoo.flv | jq '[."media"."@ref",."media"."@ref"]'

[
"higkoo.flv",
"higkoo.flv"
]

mediainfo -f --Output=JSON higkoo.flv | jq '[."media"."track"[] | select(."@type"=="General")."FileExtension"],[."media"."track"[] | select(."@type"=="General")."FileExtension"]'

[
"flv"
]
[
"flv"
]

mediainfo -f --Output=JSON higkoo.flv | jq '[."media"."track"[] | select(."@type"=="General")."FileExtension" , ."media"."track"[] | select(."@type"=="General")."FileExtension"]'

jq: error (at :65): Cannot index string with string "@type"

Expected

[
"flv",
"flv"
]

Need some value into a array then use "| @csv" output a csv file.

mediainfo -f --Output=JSON higkoo.flv | jq '[."media"."track"[] | select(."@type"=="General")."FileExtension" , ."media"."track"[] | select(."@type"=="General")."FileExtension"]'

jq: error (at :65): Cannot index string with string "@type"

Expected

[
"flv",
"flv"
]

mediainfo -f --Output=JSON higkoo.flv | jq '[."media"."track"[] | 
select(."@type"=="General")."FileExtension"] + [."media"."track"[] | 
select(."@type"=="General")."FileExtension"]'

can output your expected result.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tbelaire picture tbelaire  Â·  4Comments

thedward picture thedward  Â·  3Comments

ve3ied picture ve3ied  Â·  4Comments

LoganBarnett picture LoganBarnett  Â·  3Comments

neowulf picture neowulf  Â·  3Comments