labpack/compilers/json.py
def merge_json(*sources, output=''):

    '''
        method for merging two or more json files

    this method walks the parse tree of json data to merge the fields
    found in subsequent sources into the data structure of the initial source. 
    any number of sources can be added to the source args, but only new fields
    from subsequent sources will be added. to overwrite values in the initial
    source instead, it suffices to simply reverse the order of the sources

    PLEASE NOTE:    since there is no way to uniquely identify list items between
                    two json documents, items are not added to existing lists.

    PLEASE NOTE:    however, lists are transversed in order to evaluate keys of 
                    nested dictionaries using the first item of any subsequent list
                    as a model for the scope
    
    PLEASE NOTE:    this method makes no checks to ensure the file path of the 
                    sources exist nor the folder path to any output

    :param sources: variable-length argument list of strings with json text
    :param output: [optional] string with path to save the combined json data to file
    :return: OrderedDict (or list of OrderedDict) with merged data
    '''

    # import libraries
    from copy import deepcopy

    # define variables
    combined = None

    # open and combine sources
    src = [open(json_path).read() for json_path in sources]
    for text in src:
        data = json_lib.loads(text)
        if not isinstance(data, list) and not isinstance(data, dict):
            raise ValueError('Source documents must be either lists or dictionaries.')
        if not combined:
            combined = deepcopy(data)
        elif combined.__class__.__name__ != data.__class__.__name__:
            raise ValueError('Source documents must be the same top-level datatype.')
        else:
            combined = walk_data(combined, data)

    # save file and return combined data
    if output:
        with open(output, 'w') as f:
            f.write(json_lib.dumps(combined, indent=2))

    return combined

        method for merging two or more json files

    this method walks the parse tree of json data to merge the fields
    found in subsequent sources into the data structure of the initial source. 
    any number of sources can be added to the source args, but only new fields
    from subsequent sources will be added. to overwrite values in the initial
    source instead, it suffices to simply reverse the order of the sources

    PLEASE NOTE:    since there is no way to uniquely identify list items between
                    two json documents, items are not added to existing lists.

    PLEASE NOTE:    however, lists are transversed in order to evaluate keys of 
                    nested dictionaries using the first item of any subsequent list
                    as a model for the scope
    
    PLEASE NOTE:    this method makes no checks to ensure the file path of the 
                    sources exist nor the folder path to any output

    :param sources: variable-length argument list of strings with json text
    :param output: [optional] string with path to save the combined json data to file
    :return: OrderedDict (or list of OrderedDict) with merged data
    
method for merging two or more json files
this method walks the parse tree of json data to merge the fields
found in subsequent sources into the data structure of the initial source.
any number of sources can be added to the source args, but only new fields
from subsequent sources will be added. to overwrite values in the initial
source instead, it suffices to simply reverse the order of the sources

PLEASE NOTE:    since there is no way to uniquely identify list items between
two json documents, items are not added to existing lists.

PLEASE NOTE:    however, lists are transversed in order to evaluate keys of
nested dictionaries using the first item of any subsequent list
as a model for the scope

PLEASE NOTE:    this method makes no checks to ensure the file path of the
sources exist nor the folder path to any output
method for merging two or more json files this method walks the parse tree of json data to merge the fields found in subsequent sources into the data structure of the initial source . any number of sources can be added to the source args but only new fields from subsequent sources will be added . to overwrite values in the initial source instead it suffices to simply reverse the order of the sources PLEASE NOTE : since there is no way to uniquely identify list items between two json documents items are not added to existing lists . PLEASE NOTE : however lists are transversed in order to evaluate keys of nested dictionaries using the first item of any subsequent list as a model for the scope PLEASE NOTE : this method makes no checks to ensure the file path of the sources exist nor the folder path to any output
def merge_json(*sources, output=''):
    from copy import deepcopy
    combined = None
    src = [open(json_path).read() for json_path in sources]
    for text in src:
        data = json_lib.loads(text)
        if not isinstance(data, list) and not isinstance(data, dict):
            raise ValueError('Source documents must be either lists or dictionaries.')
        if not combined:
            combined = deepcopy(data)
        elif combined.__class__.__name__ != data.__class__.__name__:
            raise ValueError('Source documents must be the same top-level datatype.')
        else:
            combined = walk_data(combined, data)
    if output:
        with open(output, 'w') as f:
            f.write(json_lib.dumps(combined, indent=2))
    return combined
def merge_json ( * sources , output = '' ) : from copy import deepcopy combined = None src = [ open ( json_path ) . read ( ) for json_path in sources ] for text in src : data = json_lib . loads ( text ) if not isinstance ( data , list ) and not isinstance ( data , dict ) : raise ValueError ( 'Source documents must be either lists or dictionaries.' ) if not combined : combined = deepcopy ( data ) elif combined . __class__ . __name__ != data . __class__ . __name__ : raise ValueError ( 'Source documents must be the same top-level datatype.' ) else : combined = walk_data ( combined , data ) if output : with open ( output , 'w' ) as f : f . write ( json_lib . dumps ( combined , indent = 2 ) ) return combined
method for merging two or more json files
this method walks the parse tree of json data to merge the fields
found in subsequent sources into the data structure of the initial source.
method for merging two or more json files this method walks the parse tree of json data to merge the fields found in subsequent sources into the data structure of the initial source .
'''
        method for merging two or more json files

    this method walks the parse tree of json data to merge the fields
    found in subsequent sources into the data structure of the initial source. 
    any number of sources can be added to the source args, but only new fields
    from subsequent sources will be added. to overwrite values in the initial
    source instead, it suffices to simply reverse the order of the sources

    PLEASE NOTE:    since there is no way to uniquely identify list items between
                    two json documents, items are not added to existing lists.

    PLEASE NOTE:    however, lists are transversed in order to evaluate keys of 
                    nested dictionaries using the first item of any subsequent list
                    as a model for the scope
    
    PLEASE NOTE:    this method makes no checks to ensure the file path of the 
                    sources exist nor the folder path to any output

    :param sources: variable-length argument list of strings with json text
    :param output: [optional] string with path to save the combined json data to file
    :return: OrderedDict (or list of OrderedDict) with merged data
    ''' # import libraries # define variables # open and combine sources # save file and return combined data
OrderedDict (or list of OrderedDict) with merged data
OrderedDict ( or list of OrderedDict ) with merged data
output
[optional] string with path to save the combined json data to file
[ optional ] string with path to save the combined json data to file
sources
variable-length argument list of strings with json text
variable - length argument list of strings with json text