How to use the jsonpath.JSONPath 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 Cryptonomic / ConseilJS / src / chain / tezos / contracts / TCFBakerRegistryHelper.ts View on Github external
export async function queryRegistration(server: string, mapid: number, baker: string) {
        const key = TezosMessageUtils.encodeBigMapKey(Buffer.from(TezosMessageUtils.writePackedData(baker, 'key_hash'), 'hex'));
        const mapResult = await TezosNodeReader.getValueForBigMapKey(server, mapid, key);

        if (!!!mapResult) { return undefined; }

        const jsonpath = new JSONPath();
        const textDecoder = new TextDecoder();

        const paymentConfigMask = Number(jsonpath.query(mapResult, '$.args[0].args[0].args[0].args[1].args[1].args[1].args[0].args[1].int')[0]); // paymentConfigMask

        return {
            name: textDecoder.decode(Buffer.from(jsonpath.query(mapResult, '$.args[0].args[0].args[0].args[0].args[0].args[0].bytes')[0], 'hex')), // bakerName
            isAcceptingDelegation: Boolean(jsonpath.query(mapResult, '$.args[0].args[0].args[0].args[0].args[0].args[1].prim')[0]), // openForDelegation
            externalDataURL: textDecoder.decode(Buffer.from(jsonpath.query(mapResult, '$.args[0].args[0].args[0].args[0].args[1].bytes')[0], 'hex')), // bakerOffchainRegistryUrl
            split: Number(jsonpath.query(mapResult, '$.args[0].args[0].args[0].args[1].args[0].args[0].int')[0]) / 10000, // split
            paymentAccounts: jsonpath.query(mapResult, '$.args[0].args[0].args[0].args[1].args[0].args[1]..string'), // bakerPaysFromAccounts
            minimumDelegation: Number(jsonpath.query(mapResult, '$.args[0].args[0].args[0].args[1].args[1].args[0].args[0].args[0].int')[0]), // minDelegation
            isGreedy: Boolean(jsonpath.query(mapResult, '$.args[0].args[0].args[0].args[1].args[1].args[0].args[0].args[1].prim')[0]), // subtractPayoutsLessThanMin
            payoutDelay: Number(jsonpath.query(mapResult, '$.args[0].args[0].args[0].args[1].args[1].args[0].args[1].args[0].int')[0]), // payoutDelay
            payoutFrequency: Number(jsonpath.query(mapResult, '$.args[0].args[0].args[0].args[1].args[1].args[0].args[1].args[1].args[0].int')[0]), // payoutFrequency
            minimumPayout: Number(jsonpath.query(mapResult, '$.args[0].args[0].args[0].args[1].args[1].args[0].args[1].args[1].args[1].int')[0]), // minPayout
            isCheap: Boolean(jsonpath.query(mapResult, '$.args[0].args[0].args[0].args[1].args[1].args[1].args[0].args[0].prim')[0]), // bakerChargesTransactionFee
github Cryptonomic / ConseilJS / src / chain / tezos / contracts / TCFBakerRegistryHelper.ts View on Github external
export async function getFees(server: string, address: string) {
        const storageResult = await TezosNodeReader.getContractStorage(server, address);
        const jsonpath = new JSONPath();

        return {
            mapid: parseInt(jsonpath.query(storageResult, '$.args[0].int')[0]),
            owner: jsonpath.query(storageResult, '$.args[1].args[0].string')[0],
            signupFee: parseInt(jsonpath.query(storageResult, '$.args[1].args[1].args[0].int')[0]),
            updateFee: parseInt(jsonpath.query(storageResult, '$.args[1].args[1].args[1].int')[0])
        };
    }

jsonpath

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

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis