1

I have a simple query for most of the times it is simple to export the parsed JSON file to various formats including the CSV format. See for reference Convert a JSON into CSV using jq

I want to define ; as a delimiter for export to csv file in the following command in the jupyter-lab magic cell

for file in filelist:
    ! echo $file
    ! jq -r '[.user.screen_name, .user.followers_count, .retweeted_status.user.screen_name,\
    .full_text, .display_text_range[1], .created_at, .id, .in_reply_to_user_id, \
    .in_reply_to_status_id, .user.location, .place.name,\
    .user.verified, .retweet_count, .favorite_count, .entities.media[].type, 
    .entities.hashtags[].text] | @csv' < $file >> $store_file

tks!

peak
  • 105,803
  • 17
  • 152
  • 177
ambrish dhaka
  • 689
  • 7
  • 27

1 Answers1

1

You might be able to get away with using join(";"), but it would almost certainly be better to use gsub(";";"\\;") on strings first, but it depends on how you want to handle semicolons in JSON strings. Depending on your requirements or expectations, you might also want to consider using @tsv and then postprocessing the tabs, e.g. using

sed $'s/\t/;/g'

or

tr '\t' ';'
peak
  • 105,803
  • 17
  • 152
  • 177