Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to convert "all_techniques" to json file #23

Closed
uestc-toy opened this issue Mar 11, 2021 · 1 comment
Closed

Fail to convert "all_techniques" to json file #23

uestc-toy opened this issue Mar 11, 2021 · 1 comment

Comments

@uestc-toy
Copy link

I want to convert "all_techniques" to JSON file by "json.dump" function.howerver, it reports errors "TypeError: Object of type AttackPattern is not JSON serializable"

lift = attack_client() all_techniques = lift.get_techniques() all_techniques = lift.remove_revoked(all_techniques)

@Cyb3rWard0g
Copy link
Collaborator

Hello @uestc-toy !

That is not an issue with the library. The output of those functions is correct. With get_techniques() and other functions that returns objects from ATT&CK TAXII, they are STIX objects. Therefore, you cannot simply use json.dumps() against the list.

You first have to serialize each STIX object in the list that you get back, then use json.loads to convert each object to a dictionary and then take the list of dictionaries and then run json.dumos(). Finally, you can export that to a JSON file.

This is what it would look like

image

The code I used:

from attackcti import attack_client
lift = attack_client()
all_techniques = lift.get_techniques()

import json
all_techniques_serialized = list(map(lambda x: json.loads(x.serialize()), all_techniques))
all_techniques_json = json.dumps(all_techniques_serialized)

I will close this issue since that would get you right to export the data to a json file. Feel free to re-open this issue.

Thank you for testing our library!

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

No branches or pull requests

2 participants