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

Inconsistent JSON representation (Observables) #208

Open
marlontaylor opened this issue Oct 8, 2014 · 0 comments
Open

Inconsistent JSON representation (Observables) #208

marlontaylor opened this issue Oct 8, 2014 · 0 comments

Comments

@marlontaylor
Copy link

Posted on both python-stix/cybox.
Please close/remove if this is not the appropriate project.

Expected an array but got an object(which contains array).

input.xml

<?xml version="1.0" encoding="UTF-8" ?>
<stix:STIX_Package 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:stix="http://stix.mitre.org/stix-1" 
xmlns:stixCommon="http://stix.mitre.org/common-1" 
xmlns:cybox="http://cybox.mitre.org/cybox-2" 
xsi:schemaLocation="
http://stix.mitre.org/stix-1 http://stix.mitre.org/XMLSchema/core/1.1/stix_core.xsd 
http://stix.mitre.org/common-1 http://stix.mitre.org/XMLSchema/common/1.1/stix_common.xsd 
http://cybox.mitre.org/cybox-2 http://cybox.mitre.org/XMLSchema/core/2.1/cybox_core.xsd 
" 
xmlns:example_namespace="http://example_namespace" version="1.1.1">
  <stix:Observables cybox_major_version="2" cybox_minor_version="1" cybox_update_version="0">
    <cybox:Observable id="example_namespace:Observable-86dc0bfe-814a-4e68-95f2-e77effb2d00a">
      <cybox:Object id="example_namespace:Object-21fe4d10-9b4c-4b1c-b6e6-871d430f25d3" />
    </cybox:Observable>
    <cybox:Observable id="example_namespace:Observable-e042e6e7-1a7c-433e-8b57-507d69999d02">
      <cybox:Title>plain title</cybox:Title>
      <cybox:Description>plain description</cybox:Description>
      <cybox:Object id="example_namespace:Object-b2da9377-1346-4288-9a35-cd0b2072906d" />
    </cybox:Observable>
  </stix:Observables>
</stix:STIX_Package>

script.py

#!/usr/bin/env python
# Copyright (c) 2014, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.

'''
File: ex_01.py

Description: Round-trip example. This script takes a STIX instance document from XML to
a binding object, then to a api object and then to a dictionary. That dictionary is then
converted back into an api object, which is then used to generate an XML document.
'''

import io
from pprint import pprint

from stix.core import STIXPackage

def main():
   fn = 'input.xml'
   stix_package = STIXPackage.from_xml(fn)
   stix_dict = stix_package.to_dict() # parse to dictionary
   pprint(stix_dict)

   stix_package_two = STIXPackage.from_dict(stix_dict) # create python-stix object from dictionary
   xml = stix_package_two.to_xml() # generate xml from python-stix object
   print(xml)

if __name__ == '__main__':
   main()

output.json

{
   "observables":{
      "observables":[
         {
            "object":{
               "id":"STIX_EDITOR:Object-21fe4d10-9b4c-4b1c-b6e6-871d430f25d3"
            },
            "id":"STIX_EDITOR:Observable-86dc0bfe-814a-4e68-95f2-e77effb2d00a"
         },
         {
            "description":"plain description",
            "object":{
               "id":"STIX_EDITOR:Object-b2da9377-1346-4288-9a35-cd0b2072906d"
            },
            "id":"STIX_EDITOR:Observable-e042e6e7-1a7c-433e-8b57-507d69999d02",
            "title":"plain title"
         }
      ],
      "major_version":2,
      "update_version":0,
      "minor_version":1
   },
   "version":"1.1.1"
}
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

1 participant