How to use the jsonpath.parent function in jsonpath

To help you get started, we’ve selected a few jsonpath examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sdawood / dynamo-update-expression / src / dynamo-update-expression.spec.js View on Github external
const applyDeletes = (document, deletes, nullify = true) => {
        const modified = _.cloneDeep(document);
        // const modified = JSON.parse(JSON.stringify(document));
        for (const path of deletes) {
            const parent = jp.parent(modified, path);
            if (_.isArray(parent)) {
                const _subscript = /\[([\d]+)\]$/;
                const subscript = _subscript.exec(path)[1];
                if (nullify) {
                    parent[subscript] = null; // delete array['0'] doesn't work with jsonpath! list items should be deleted by setting to null or undefined,
                } else {
                    parent.splice(subscript, 1);
                }
            } else {
                delete parent[path.split('.').pop()];
            }
        }
        return modified;
    };
github midas-science / midas / source / midas.js View on Github external
if(Array.isArray(parent)) {
                            let enriched_intermediate_object = {value: node.value};
                            enriched_intermediate_object[enriched_property_name] = deep_copied_intermediate_result;
                            object_path.set(data, parent_object_path, enriched_intermediate_object);
                        } else {
                            parent[enriched_property_name] = deep_copied_intermediate_result;
                        }
                    }
                                       
                    if(typeof node.value === 'object' && !Array.isArray(node.value)) {
                        object_path.set(data, node_path + '.' + enriched_property_name, deep_copied_intermediate_result);
                     }

                    if(Array.isArray(node.value)) {
                        path_expression = jp.stringify(node.path);
                        parent = jp.parent(data, path_expression);
                        parent[enriched_property_name] = deep_copied_intermediate_result;
                    }

                    // check if there is some kind of rate limit defined within the configuration
                    if(typeof promise.getConfig().rate_limit !== 'undefined' && typeof promise.getConfig().rate_limit !== 'undefined') {
                        await RateLimiter.async_stall(promise.getConfig().rate_limit.number_of_requests, promise.getConfig().rate_limit.time_window);
                    }
                }
            
            }

            return {data: result};
        }
        return chain_enricher_promises(enrichers, self);
github midas-science / midas / source / midas.js View on Github external
promise.setData(enrichment_target);  
                    intermediate_result = enrichment_target;
                    intermediate_result = await promise.process(intermediate_result);
                    let deep_copied_intermediate_result = JSON.parse(JSON.stringify(intermediate_result));

                    // Check node type 
                    if(typeof node.value !== 'object' && !Array.isArray(node.value)) {
                        path_expression = jp.stringify(node.path);
                        let node_path_deep_copy = JSON.parse(JSON.stringify(node.path));
                        //node_path_deep_copy.pop();
                        node_path_deep_copy.shift();
                        parent_object_path = node_path_deep_copy.join('.');

                        // get parent and check if it's an array
                        parent = jp.parent(data, path_expression);
                        if(Array.isArray(parent)) {
                            let enriched_intermediate_object = {value: node.value};
                            enriched_intermediate_object[enriched_property_name] = deep_copied_intermediate_result;
                            object_path.set(data, parent_object_path, enriched_intermediate_object);
                        } else {
                            parent[enriched_property_name] = deep_copied_intermediate_result;
                        }
                    }
                                       
                    if(typeof node.value === 'object' && !Array.isArray(node.value)) {
                        object_path.set(data, node_path + '.' + enriched_property_name, deep_copied_intermediate_result);
                     }

                    if(Array.isArray(node.value)) {
                        path_expression = jp.stringify(node.path);
                        parent = jp.parent(data, path_expression);
github mmendesas / walnutjs / src / support / parser / jsonparser.js View on Github external
deleteKey: function (path) {
        const parent = jp.parent(this.jsonObj, path);
        const paths = jp.paths(this.jsonObj, path);
        const item = paths[0].pop();

        if (Array.isArray(parent)) {
            parent.splice(item, 1);
        } else {
            delete parent[item];
        }
    }
}

jsonpath

Query JavaScript objects with JSONPath expressions. Robust / safe JSONPath engine for Node.js.

MIT
Latest version published 4 years ago

Package Health Score

70 / 100
Full package analysis