Ejemplo n.º 1
0
def json_get(file):
    keys = list(map(lambda key: key.split("."), args.keys))
    for json in load(file):
        if keys:
            for subkeys in keys:
                try:
                    print(dumps(reduce(lambda get, subkey: get[subkey], subkeys, json), indent = indent))
                except:
                    pass
        else:
            print(dumps(json, indent = indent))
Ejemplo n.º 2
0
def json_remove(file):
    keys = list(map(lambda key: key.split("."), args.keys))
    for json in load(file):
        for subkeys in keys:
            try:
                remove = json
                last_index = len(subkeys) - 1
                for i in range(last_index):
                    remove = remove[subkeys[i]]
                del remove[subkeys[last_index]]
            except:
                pass
    print(dumps(json, indent=indent))
Ejemplo n.º 3
0
def json_remove(file):
    keys = list(map(lambda key: key.split("."), args.keys))
    for json in load(file):
        for subkeys in keys:
            try:
                remove = json
                last_index = len(subkeys) - 1
                for i in range(last_index):
                    remove = remove[subkeys[i]]
                del remove[subkeys[last_index]]
            except:
                pass
    print(dumps(json, indent = indent))
Ejemplo n.º 4
0
def json_put(file):
    subkeys = args.key.split(".")
    value = args.value
    last_index = len(subkeys) - 1
    last_subkey = subkeys[last_index]
    for json in load(file):
        try:
            put = json
            for i in range(last_index):
                put = put[subkeys[i]]
            put[last_subkey] = value
        except:
            pass
        print(dumps(json, indent=indent))
Ejemplo n.º 5
0
def json_get(file):
    keys = list(map(lambda key: key.split("."), args.keys))
    for json in load(file):
        if keys:
            for subkeys in keys:
                try:
                    print(
                        dumps(reduce(lambda get, subkey: get[subkey], subkeys,
                                     json),
                              indent=indent))
                except:
                    pass
        else:
            print(dumps(json, indent=indent))
Ejemplo n.º 6
0
def json_put(file):
    subkeys = args.key.split(".")
    value = args.value
    last_index = len(subkeys) - 1
    last_subkey = subkeys[last_index]
    for json in load(file):
        try:
            put = json
            for i in range(last_index):
                put = put[subkeys[i]]
            put[last_subkey] = value
        except:
            pass
        print(dumps(json, indent = indent))