Skip to content

fix: query --output should write file as list of json objects#50

Merged
yevgenypats merged 1 commit intocloudquery:mainfrom
James-Quigley:output-json-list
Jan 29, 2021
Merged

fix: query --output should write file as list of json objects#50
yevgenypats merged 1 commit intocloudquery:mainfrom
James-Quigley:output-json-list

Conversation

@James-Quigley
Copy link
Copy Markdown
Contributor

@James-Quigley James-Quigley commented Jan 29, 2021

Instead of writing each query result as an individual object line by line, write the whole thing at once as a list.

Previously the output would have been written to look like:

{}
{}

which isn't valid JSON. Now it will be written as:

[
  {},
  {}
]

This should fix #48

@yevgenypats
Copy link
Copy Markdown
Contributor

@James-Quigley Thanks for this. I have one suggestion/ask - accumulating all the results before writing to the file might be an unnecessary memory consumption (it might get big depending on the query). Currently it writes the result after each iteration, I suggest keeping it the same way but just writing a [ at the beginning and , after each row (apart from the last one).

@James-Quigley
Copy link
Copy Markdown
Contributor Author

@James-Quigley Thanks for this. I have one suggestion/ask - accumulating all the results before writing to the file might be an unnecessary memory consumption (it might get big depending on the query). Currently it writes the result after each iteration, I suggest keeping it the same way but just writing a [ at the beginning and , after each row (apart from the last one).

That's a good point. I'll update it

@yevgenypats yevgenypats merged commit 5d15860 into cloudquery:main Jan 29, 2021
@yevgenypats
Copy link
Copy Markdown
Contributor

Thanks!

@James-Quigley James-Quigley deleted the output-json-list branch January 29, 2021 22:00
erezrokah pushed a commit that referenced this pull request Aug 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request for query command to optionally return output in a machine readable format e.g. json/yaml

2 participants