tyki6 / rawsec_cli

Rawsec's Cybersecurity Inventory cli. Search pentesting tools, resources, ctf, os.
https://inventory.raw.pm
MIT License
24 stars 6 forks source link

invalid JSON output #45

Closed noraj closed 3 years ago

noraj commented 3 years ago

Describe the bug

-of json is fine and export json using double quotes, -o json is exporting json with single quotes which is invalid and so break all json parsers.

To Reproduce

$ rawsec-cli list os -of /tmp/test.json
$ rawsec-cli list os -o json > /tmp/test2.json
$ diff test.json test2.json
$ rawsec-cli list os -o json | jq             
parse error: Invalid numeric literal at line 1, column 12
$ cat test.json | jq # => ok

Expected behavior

Environment (please complete the following information):

Idea

Just replace simple quotes with double quotes (or export python dict to JSON).

tyki6 commented 3 years ago

hey @noraj thanks you for testing my code, awesome work, thanks a lot.

True i just needed to replace: this code:

click.echo({"projects": projects, "total": len(projects)})

By:

click.echo(json.dumps({"projects": projects, "total": len(projects)}))

now: rawsec-cli list os -o json | jq # => ok

noraj commented 3 years ago

I had a good guess it was a python dict vs JSON object issue.

tyki6 commented 3 years ago

yes