class_docstr: Test class for JSONParser
class_docstr_tok: ["Test","class","for","JSONParser"]
docstr: JSONParser - Optional top level keys and json path
docstr_tok: ["JSONParser","-","Optional","top","level","keys","and","json","path"]
code: def test_optional_keys_with_json_path(self):
      """JSONParser - Optional top level keys and json path"""
      options = {
          "schema": {
              "md5": "string",
              "opt_key": "string",
              "another_opt_key": "string",
          },
          "configuration": {
              "json_path": "docs[*]",
              "optional_top_level_keys": ["opt_key", "another_opt_key"],
          },
      }
  
      record_data = json.dumps(
          {
              "server": "test_server",
              "username": "test_user",
              "docs": [
                  {
                      "md5": "58B8702C20DE211D1FCB248D2FDD71D1",
                      "opt_key": "exists",
                  },
                  {
                      "md5": "1D1FCB248D2FDD71D158B8702C20DE21",
                      "opt_key": "this_value_is_optional",
                      "another_opt_key": "this_value_is_also_optional",
                  },
                  {"md5": "1D1FCB248D2FDD71D158B8702C20DE21"},
              ],
          }
      )
  
      # get parsed data
      parser = JSONParser(options)
      assert_equal(parser.parse(record_data), True)
  
      expected_result = [
          {
              "md5": "58B8702C20DE211D1FCB248D2FDD71D1",
              "opt_key": "exists",
              "another_opt_key": "",
          },
          {
              "md5": "1D1FCB248D2FDD71D158B8702C20DE21",
              "opt_key": "this_value_is_optional",
              "another_opt_key": "this_value_is_also_optional",
          },
          {
              "md5": "1D1FCB248D2FDD71D158B8702C20DE21",
              "opt_key": "",
              "another_opt_key": "",
          },
      ]
  
      assert_equal(parser.parsed_records, expected_result)
  
imports: import json
  from mock import patch
  from nose.tools import assert_equal
  from streamalert.classifier.parsers import JSONParser
label_desc: Use image node_id 20 for calling the TestJSONParser obj's underlying member method code with example usage: obj.test_optional_keys_with_json_path() without return types