How to use the jsonpointer.compile function in jsonpointer

To help you get started, we’ve selected a few jsonpointer 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 sonnyp / JSON8 / packages / pointer / benchmark.js View on Github external
const manuelstofer = require("json-pointer"); // https://github.com/manuelstofer/json-pointer
const flitbit = require("json-ptr"); // https://github.com/flitbit/json-ptr

const doc = {
  foo: [1, 2, 3, 4], // eslint-disable-line no-magic-numbers
  baz: [
    {
      qux: "hello",
    },
  ],
};

const pointer = "/baz/0/qux";
const compiled = ooPointer.compile(pointer);

const janlCompiled = jsonpointer.compile(pointer);

const evaluate = jsonpointerjs.get(doc);

const ptr = flitbit.create(pointer);

const suite = benchmark.Suite("pointer");

suite
  .add("find", function() {
    ooPointer.find(doc, pointer);
  })
  .add("compiled", function() {
    compiled(doc);
  })
  .add("compile + compiled", function() {
    ooPointer.compile(pointer)(doc);
github Altinn / altinn-studio / src / Altinn.Apps / AppFrontend / react / altinn-app-frontend / src / utils / databindings.ts View on Github external
export const filterFormData = (data: any, model: any): any => {
  const filteredResult: any = {};
  const rootKey = Object.keys(model.properties)[0];
  const modelPath = model.properties[rootKey].$ref.slice(1);
  const pointer = JsonPointer.compile(modelPath);
  const root: any = pointer.get(model);
  Object.keys(data).forEach((key: string) => {
    const formDataKey = getKeyWithoutIndex(key);
    const formDataRoot = formDataKey.split('.')[0];
    const element = root.properties[formDataRoot];
    if (element && (!element['@xsdType'] || element['@xsdType'] !== 'XmlAttribute')) {
      filteredResult[key] = data[key];
    }
  });
  return filteredResult;
};
github Altinn / altinn-studio / src / Altinn.Apps / AppFrontend / react / altinn-app-frontend / src / utils / validation.ts View on Github external
export function createValidator(schema: any): ISchemaValidator {
  const ajv = new Ajv({ allErrors: true, coerceTypes: true });
  ajv.addFormat('year', /^[0-9]{4}$/);
  ajv.addSchema(schema, 'schema');
  const rootKey = Object.keys(schema.properties)[0];
  const rootElementPath = schema.properties[rootKey].$ref;
  const rootPtr = JsonPointer.compile(rootElementPath.substr(1));
  const rootElement = rootPtr.get(schema);
  const schemaValidator: ISchemaValidator = {
    validator: ajv,
    schema,
    rootElement,
    rootElementPath,
  };
  return schemaValidator;
}
github Altinn / altinn-studio / src / Altinn.Apps / AppFrontend / react / altinn-app-frontend / src / utils / validation.ts View on Github external
const dataModelRoot = dataModelPath[0];
  if (subSchema.properties && subSchema.properties[dataModelRoot] && dataModelPath && dataModelPath.length !== 0) {
    const localRootElement = subSchema.properties[dataModelRoot];
    if (localRootElement.$ref) {
      const childSchemaPtr = JsonPointer.compile(localRootElement.$ref.substr(1));
      return getSchemaPart(dataModelPath.slice(1), childSchemaPtr.get(mainSchema), mainSchema);
    }
    if (localRootElement.items && localRootElement.items.$ref) {
      const childSchemaPtr = JsonPointer.compile(localRootElement.items.$ref.substr(1));
      return getSchemaPart(dataModelPath.slice(1), childSchemaPtr.get(mainSchema), mainSchema);
    }
    return localRootElement;
  }

  if (subSchema.$ref) {
    const ptr = JsonPointer.compile(subSchema.$ref.substr(1));
    return getSchemaPart(dataModelPath.slice(1), ptr.get(mainSchema), mainSchema);
  }

  return subSchema;
}
github slurmulon / json-where / src / pointer.js View on Github external
matches(rel) {
    if (rel && !rel.constructor === String) {
      return false
    }

    try {
      return jsonPointer.compile(rel) instanceof Object
    } catch (e) {
      return false
    }
  }
github Altinn / altinn-studio / src / Altinn.Apps / AppFrontend / react / altinn-app-frontend / src / utils / validation.ts View on Github external
export function getSchemaPart(dataModelPath: string[], subSchema: any, mainSchema: any) {
  const dataModelRoot = dataModelPath[0];
  if (subSchema.properties && subSchema.properties[dataModelRoot] && dataModelPath && dataModelPath.length !== 0) {
    const localRootElement = subSchema.properties[dataModelRoot];
    if (localRootElement.$ref) {
      const childSchemaPtr = JsonPointer.compile(localRootElement.$ref.substr(1));
      return getSchemaPart(dataModelPath.slice(1), childSchemaPtr.get(mainSchema), mainSchema);
    }
    if (localRootElement.items && localRootElement.items.$ref) {
      const childSchemaPtr = JsonPointer.compile(localRootElement.items.$ref.substr(1));
      return getSchemaPart(dataModelPath.slice(1), childSchemaPtr.get(mainSchema), mainSchema);
    }
    return localRootElement;
  }

  if (subSchema.$ref) {
    const ptr = JsonPointer.compile(subSchema.$ref.substr(1));
    return getSchemaPart(dataModelPath.slice(1), ptr.get(mainSchema), mainSchema);
  }

  return subSchema;
}

jsonpointer

Simple JSON Addressing.

MIT
Latest version published 2 years ago

Package Health Score

77 / 100
Full package analysis

Similar packages