def _folder_to_json(jdir, key_path=None, in_memory=True,
                    ignore_prefix=('.', '_'), dic={}, parse_decimal=False):
    """ read in folder structure as json

    e.g.

    jdir
        sub_dir1
            data.json
        sub_dir2
            data.json

    _folder_to_json(jdir)
    => {'sub_dir1':{'data':{...}},
        'sub_dir2':{'data':{...}}}

    NB: json files are identified with .json extension

    """
    key_path = [] if key_path is None else key_path

    if not hasattr(jdir, 'iterdir'):
        raise ValueError('jdir is not a path object; {}'.format(jdir))

    key_found = False if key_path else True
    search_key = key_path[0] if len(key_path) > 0 else None

    for jsub in jdir.iterdir():
        if jsub.is_file() and jsub.name.endswith('.json'):

            name, ext = os.path.splitext(jsub.name)
            if name == search_key or not key_path:
                key_found = True
                if key_path:
                    data = to_dict(jsub, key_path[1:], in_memory,
                                   ignore_prefix, parse_decimal)
                    if isinstance(data, dict):
                        dic.update(data)
                    else:
                        dic.update({_Terminus(): data})
                else:
                    dic[name] = to_dict(jsub, key_path[1:], in_memory,
                                        ignore_prefix, parse_decimal)

        elif (jsub.is_dir()
              and not jsub.name.startswith(ignore_prefix)
              and (jsub.name == search_key or not key_path)):

            key_found = True
            if jsub.name in dic.keys():
                raise IOError(
                    'directory has a sub-dir and file with same name: '
                    '{1} and {1}.json in {0}'.format(jdir, jsub.name))
            if key_path:
                sub_d = dic
            else:
                dic[jsub.name] = {}
                sub_d = dic[jsub.name]
            _folder_to_json(jsub, key_path[1:], in_memory, ignore_prefix,
                            sub_d, parse_decimal)

    if not key_found:
        raise KeyError('key not found: {0}'.format(search_key))
read in folder structure as json

    e.g.

    jdir
        sub_dir1
            data.json
        sub_dir2
            data.json

    _folder_to_json(jdir)
    => {'sub_dir1':{'data':{...}},
        'sub_dir2':{'data':{...}}}

    NB: json files are identified with .json extension