How to use jsonpointer - 10 common examples

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 nickcmaynard / jsonschemalint / draft4 / js / is-my-json-valid / is-my-json-valid.js View on Github external
var visit = function(sub) {
    if (sub && sub.id === ptr) return sub
    if (typeof sub !== 'object' || !sub) return null
    return Object.keys(sub).reduce(function(res, k) {
      return res || visit(sub[k])
    }, null)
  }

  var res = visit(obj)
  if (res) return res

  ptr = ptr.replace(/^#/, '')
  ptr = ptr.replace(/\/$/, '')

  try {
    return jsonpointer.get(obj, decodeURI(ptr))
  } catch (err) {
    var end = ptr.indexOf('#')
    var other
    // external reference
    if (end !== 0) {
      // fragment doesn't exist.
      if (end === -1) {
        other = additionalSchemas[ptr]
      } else {
        var ext = ptr.slice(0, end)
        other = additionalSchemas[ext]
        var fragment = ptr.slice(end).replace(/^#/, '')
        try {
          return jsonpointer.get(other, fragment)
        } catch (err) {}
      }
github netlify / build / packages / git-utils / src / unused.js View on Github external
return diff.reduce((accumulator, { path }) => {
    // We don't want to show the last root object, as these tend to just go directly
    // to a single value in the patch. This is fine, but not useful when showing a before/after
    const pathSteps = path.split('/')
    const backAStepPath = pathSteps.length <= 2 ? path : pathSteps.slice(0, pathSteps.length - 1).join('/')
    const diff = {
      after: jsonpointer.get(after, backAStepPath) || null,
      before: jsonpointer.get(before, backAStepPath) || null,
    }
    const emptyValueOfCounterpart = other => {
      if (Array.isArray(other)) {
        return []
      } else if (isobject(diff.after)) {
        return {}
      }
      return null
    }
    const beforeValue = diff.before || emptyValueOfCounterpart(diff.after)
    const afterValue = diff.after || emptyValueOfCounterpart(diff.before)
    // If they both are arrays, add some extra metadata about what was
    // added or removed. This makes it really easy to act on specific
    // changes to JSON DSLs
    if (Array.isArray(afterValue) && Array.isArray(beforeValue)) {
github PacktPublishing / JavaScript--Functional-Programming-for-JavaScript-Developers / Module 1 / Chapter09 / request / node_modules / har-validator / node_modules / is-my-json-valid / index.js View on Github external
try {
    return jsonpointer.get(obj, decodeURI(ptr))
  } catch (err) {
    var end = ptr.indexOf('#')
    var other
    // external reference
    if (end !== 0) {
      // fragment doesn't exist.
      if (end === -1) {
        other = additionalSchemas[ptr]
      } else {
        var ext = ptr.slice(0, end)
        other = additionalSchemas[ext]
        var fragment = ptr.slice(end).replace(/^#/, '')
        try {
          return jsonpointer.get(other, fragment)
        } catch (err) {}
      }
    } else {
      other = additionalSchemas[ptr]
    }
    return other || null
  }
}
github bloomreach / experience-react-sdk / packages / sdk / src / utils / create-link.js View on Github external
let href = null;
  let internalLink = null;

  // eslint-disable-next-line default-case
  switch (linkType) {
    case 'self':
      href = getNestedObject(link, ['_links', 'site', 'href']);
      internalLink = getNestedObject(link, ['_links', 'site', 'type']);
      break;

    case 'ref':
      if (!link || !isString(link)) {
        break;
      }
      // eslint-disable-next-line no-case-declarations
      const linkedContent = jsonpointer.get(pageModel, link);
      if (linkedContent) {
        href = getNestedObject(linkedContent, ['_links', 'site', 'href']);
        internalLink = getNestedObject(linkedContent, ['_links', 'site', 'type']);
      }
      break;

    case 'href':
      href = link;
      internalLink = 'internal';
      break;
  }

  // linkText is a function insteaf of a string, so that additional HTML can be included inside the anchor tag
  if (href && internalLink && typeof linkText === 'function') {
    return internalLink === 'internal' && typeof externalCreateLinkFunction === 'function'
      ? externalCreateLinkFunction(href, linkText, className)
github neuroanatomy / BrainBox / public / js / node_modules / request / node_modules / har-validator / node_modules / is-my-json-valid / index.js View on Github external
try {
    return jsonpointer.get(obj, decodeURI(ptr))
  } catch (err) {
    var end = ptr.indexOf('#')
    var other
    // external reference
    if (end !== 0) {
      // fragment doesn't exist.
      if (end === -1) {
        other = additionalSchemas[ptr]
      } else {
        var ext = ptr.slice(0, end)
        other = additionalSchemas[ext]
        var fragment = ptr.slice(end).replace(/^#/, '')
        try {
          return jsonpointer.get(other, fragment)
        } catch (err) {}
      }
    } else {
      other = additionalSchemas[ptr]
    }
    return other || null
  }
}
github nickcmaynard / jsonschemalint / draft4 / js / is-my-json-valid / is-my-json-valid.js View on Github external
try {
    return jsonpointer.get(obj, decodeURI(ptr))
  } catch (err) {
    var end = ptr.indexOf('#')
    var other
    // external reference
    if (end !== 0) {
      // fragment doesn't exist.
      if (end === -1) {
        other = additionalSchemas[ptr]
      } else {
        var ext = ptr.slice(0, end)
        other = additionalSchemas[ext]
        var fragment = ptr.slice(end).replace(/^#/, '')
        try {
          return jsonpointer.get(other, fragment)
        } catch (err) {}
      }
    } else {
      other = additionalSchemas[ptr]
    }
    return other || null
  }
}
github Fuhua-Chen / ReSpeaker-Microphone-Array-HID-tool / node-hid / node_modules / is-my-json-valid / index.js View on Github external
try {
    return jsonpointer.get(obj, decodeURI(ptr))
  } catch (err) {
    var end = ptr.indexOf('#')
    var other
    // external reference
    if (end !== 0) {
      // fragment doesn't exist.
      if (end === -1) {
        other = additionalSchemas[ptr]
      } else {
        var ext = ptr.slice(0, end)
        other = additionalSchemas[ext]
        var fragment = ptr.slice(end).replace(/^#/, '')
        try {
          return jsonpointer.get(other, fragment)
        } catch (err) {}
      }
    } else {
      other = additionalSchemas[ptr]
    }
    return other || null
  }
}
github CodeTengu / LambdaBaku / functions / share_issue_on_twitter / node_modules / twit / node_modules / request / node_modules / har-validator / node_modules / is-my-json-valid / index.js View on Github external
try {
    return jsonpointer.get(obj, decodeURI(ptr))
  } catch (err) {
    var end = ptr.indexOf('#')
    var other
    // external reference
    if (end !== 0) {
      // fragment doesn't exist.
      if (end === -1) {
        other = additionalSchemas[ptr]
      } else {
        var ext = ptr.slice(0, end)
        other = additionalSchemas[ext]
        var fragment = ptr.slice(end).replace(/^#/, '')
        try {
          return jsonpointer.get(other, fragment)
        } catch (err) {}
      }
    } else {
      other = additionalSchemas[ptr]
    }
    return other || null
  }
}
github splunk / splunk-sdk-javascript / node_modules / request / node_modules / har-validator / node_modules / is-my-json-valid / index.js View on Github external
try {
    return jsonpointer.get(obj, decodeURI(ptr))
  } catch (err) {
    var end = ptr.indexOf('#')
    var other
    // external reference
    if (end !== 0) {
      // fragment doesn't exist.
      if (end === -1) {
        other = additionalSchemas[ptr]
      } else {
        var ext = ptr.slice(0, end)
        other = additionalSchemas[ext]
        var fragment = ptr.slice(end).replace(/^#/, '')
        try {
          return jsonpointer.get(other, fragment)
        } catch (err) {}
      }
    } else {
      other = additionalSchemas[ptr]
    }
    return other || null
  }
}
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);

jsonpointer

Simple JSON Addressing.

MIT
Latest version published 2 years ago

Package Health Score

77 / 100
Full package analysis

Similar packages