1 # Copyright (c) 2016 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """Used to parse Json files or Json data strings to dictionaries"""
19 class JsonParser(object):
20 """Parses Json data string or files containing Json data strings"""
25 def parse_data(json_data):
26 """Return list parsed from json data string.
28 Translates json data into list of values/dictionaries/lists
29 :param json_data: data in json format
30 :return: json data parsed as python list
32 parsed_data = json.loads(json_data)
35 def parse_file(self, json_file):
36 """Return list parsed from file containing json string.
38 Translates json data found in file into list of
39 values/dictionaries/lists
40 :param json_file: file with json type data
41 :return: json data parsed as python list
43 input_data = open(json_file).read()
44 parsed_data = self.parse_data(input_data)