All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions | Variables
python.merge_json Namespace Reference

Functions

def merge_json_objects
 
def merge_json_files
 

Variables

list json_filenames = sys.argv[1:]
 

Function Documentation

def python.merge_json.merge_json_files (   json_filenames)

Definition at line 48 of file merge_json.py.

48 
49 def merge_json_files(json_filenames):
50 
51  # Decode all json files into json objects.
52 
53  json_objects = []
54  for json_filename in json_filenames:
55  json_file = open(json_filename)
56  if not json_file:
57  raise IOError('Unable to open json file %s.' % json_filename)
58  obj = json.load(json_file)
59  json_objects.append(obj)
60 
61  # Combine json objects into a single result object.
62 
63  merged = merge_json_objects(json_objects)
64  print(json.dumps(merged, indent=2, sort_keys=True))
do one_file $F done echo for F in find $TOP name CMakeLists txt print
open(RACETRACK) or die("Could not open file $RACETRACK for writing")
def python.merge_json.merge_json_objects (   json_objects)

Definition at line 26 of file merge_json.py.

26 
27 def merge_json_objects(json_objects):
28 
29  merged = {}
30 
31  # Loop over input objects and insert all keys into merged object.
32  # It is an error if the same key is encountered twice unless tha values
33  # are identical.
34 
35  for json_object in json_objects:
36  for key in list(json_object.keys()):
37  if key in list(merged.keys()):
38  if json_object[key] != merged[key]:
39  raise RuntimeError('Duplicate nonmatching key %s.' % key)
40  else:
41  merged[key] = json_object[key]
42 
43  # Done.
44 
45  return merged
46 
47 # Function to merge json files and print the result on standard output.
list
Definition: file_to_url.sh:28

Variable Documentation

list python.merge_json.json_filenames = sys.argv[1:]

Definition at line 67 of file merge_json.py.