• Get Review Board
  • What's New
  • Products
  • Review Board Code review, image review, and document review
  • Documentation
  • Release Notes
  • Power Pack Enterprise integrations, reports, and enhanced document review
  • Try for 60 Days
  • Purchase
  • RBCommons Review Board as a Service, hosted by us
  • Pricing
  • RBTools Command line tools and Python API for Review Board
  • Documentation
  • Release Notes
  • Review Bot Automated code review, connecting tools you already use
  • Documentation
  • Release Notes
  • RB Gateway Manage Git and Mercurial repositories in your network
  • Documentation
  • Release Notes
  • Learn and Explore
  • What is Code Review?
  • Documentation
  • Frequently Asked Questions
  • Support Options
  • Third-Party Integrations
  • Demo
  • Review Board RBTools Power Pack Review Bot Djblets RB Gateway
    1. Djblets 5.x
    2. Version 5.x
    3. Version 4.x
    4. Version 3.x
    5. Version 2.x
    6. Version 2.0
    7. Version 1.0
    8. Version 0.9
    9. Djblets Documentation
    10. Module and Class References
    11. djblets.util.json_utils
  • Home
  • Guides
  • Avatar Services Guides
  • Writing Avatar Services
  • Extension Guides
  • Writing Extensions
  • Testing Extensions
  • Feature Checks Guides
  • Introduction to Feature Checks
  • Writing Features
  • Writing Feature Checkers
  • Testing with Feature Checks
  • Integration Guides
  • Supporting Integrations
  • Writing Integrations
  • Privacy Compliance Guides
  • Getting and Checking Consent
  • Working with Personally Identifiable Information
  • Service Integrations
  • reCAPTCHA Guides
  • Using reCAPTCHA
  • Registries Guides
  • Writing Registries
  • Web API Guides
  • Writing Web API Resources
  • Adding OAuth2 Support
  • Module and Class References
  • djblets
  • djblets.deprecation
  • djblets.auth.forms
  • djblets.auth.ratelimit
  • djblets.auth.signals
  • djblets.auth.util
  • djblets.auth.views
  • djblets.avatars.errors
  • djblets.avatars.forms
  • djblets.avatars.registry
  • djblets.avatars.services
  • djblets.avatars.services.base
  • djblets.avatars.services.fallback
  • djblets.avatars.services.file_upload
  • djblets.avatars.services.gravatar
  • djblets.avatars.services.url
  • djblets.avatars.settings
  • djblets.cache.backend
  • djblets.cache.backend_compat
  • djblets.cache.context_processors
  • djblets.cache.errors
  • djblets.cache.forwarding_backend
  • djblets.cache.serials
  • djblets.cache.synchronizer
  • djblets.conditions
  • djblets.conditions.choices
  • djblets.conditions.conditions
  • djblets.conditions.errors
  • djblets.conditions.operators
  • djblets.conditions.values
  • djblets.configforms.forms
  • djblets.configforms.mixins
  • djblets.configforms.pages
  • djblets.configforms.registry
  • djblets.configforms.views
  • djblets.datagrid.grids
  • djblets.db.backends.mysql.base
  • djblets.db.fields
  • djblets.db.fields.base64_field
  • djblets.db.fields.comma_separated_values_field
  • djblets.db.fields.counter_field
  • djblets.db.fields.json_field
  • djblets.db.fields.modification_timestamp_field
  • djblets.db.fields.relation_counter_field
  • djblets.db.managers
  • djblets.db.query
  • djblets.db.query_catcher
  • djblets.db.query_comparator
  • djblets.db.validators
  • djblets.extensions.admin
  • djblets.extensions.errors
  • djblets.extensions.extension
  • djblets.extensions.forms
  • djblets.extensions.hooks
  • djblets.extensions.loaders
  • djblets.extensions.manager
  • djblets.extensions.middleware
  • djblets.extensions.models
  • djblets.extensions.packaging
  • djblets.extensions.resources
  • djblets.extensions.settings
  • djblets.extensions.signals
  • djblets.extensions.staticfiles
  • djblets.extensions.testing
  • djblets.extensions.testing.testcases
  • djblets.extensions.urls
  • djblets.extensions.views
  • djblets.extensions.templatetags.djblets_extensions
  • djblets.features
  • djblets.features.checkers
  • djblets.features.decorators
  • djblets.features.errors
  • djblets.features.feature
  • djblets.features.level
  • djblets.features.registry
  • djblets.features.testing
  • djblets.features.templatetags.features
  • djblets.forms.fields
  • djblets.forms.fieldsets
  • djblets.forms.forms
  • djblets.forms.forms.key_value_form
  • djblets.forms.widgets
  • djblets.gravatars
  • djblets.gravatars.templatetags.gravatars
  • djblets.http.middleware
  • djblets.http.responses
  • djblets.integrations.errors
  • djblets.integrations.forms
  • djblets.integrations.hooks
  • djblets.integrations.integration
  • djblets.integrations.manager
  • djblets.integrations.mixins
  • djblets.integrations.models
  • djblets.integrations.urls
  • djblets.integrations.views
  • djblets.log
  • djblets.log.middleware
  • djblets.log.siteconfig
  • djblets.log.urls
  • djblets.log.views
  • djblets.mail.dmarc
  • djblets.mail.message
  • djblets.mail.testing
  • djblets.mail.utils
  • djblets.markdown
  • djblets.markdown.extensions.escape_html
  • djblets.markdown.extensions.wysiwyg
  • djblets.markdown.extensions.wysiwyg_email
  • djblets.pipeline.compilers.es6
  • djblets.pipeline.compilers.less
  • djblets.pipeline.compilers.mixins
  • djblets.pipeline.compilers.rollup
  • djblets.pipeline.compilers.typescript
  • djblets.pipeline.settings
  • djblets.privacy.consent
  • djblets.privacy.consent.base
  • djblets.privacy.consent.common
  • djblets.privacy.consent.errors
  • djblets.privacy.consent.forms
  • djblets.privacy.consent.hooks
  • djblets.privacy.consent.registry
  • djblets.privacy.consent.tracker
  • djblets.privacy.models
  • djblets.privacy.pii
  • djblets.privacy.templatetags.djblets_privacy
  • djblets.recaptcha.mixins
  • djblets.recaptcha.siteconfig
  • djblets.recaptcha.templatetags.djblets_recaptcha
  • djblets.recaptcha.widgets
  • djblets.registries
  • djblets.registries.errors
  • djblets.registries.importer
  • djblets.registries.mixins
  • djblets.registries.registry
  • djblets.registries.signals
  • djblets.secrets
  • djblets.secrets.crypto
  • djblets.secrets.token_generators
  • djblets.secrets.token_generators.base
  • djblets.secrets.token_generators.legacy_sha1
  • djblets.secrets.token_generators.registry
  • djblets.secrets.token_generators.vendor_checksum
  • djblets.siteconfig
  • djblets.siteconfig.admin
  • djblets.siteconfig.context_processors
  • djblets.siteconfig.django_settings
  • djblets.siteconfig.forms
  • djblets.siteconfig.managers
  • djblets.siteconfig.middleware
  • djblets.siteconfig.models
  • djblets.siteconfig.signals
  • djblets.siteconfig.views
  • djblets.template.caches
  • djblets.template.context
  • djblets.template.loaders.conditional_cached
  • djblets.template.loaders.namespaced_app_dirs
  • djblets.testing.decorators
  • djblets.testing.testcases
  • djblets.testing.testrunners
  • djblets.urls.context_processors
  • djblets.urls.decorators
  • djblets.urls.patterns
  • djblets.urls.resolvers
  • djblets.urls.root
  • djblets.urls.staticfiles
  • djblets.util.compat.django.core.cache
  • djblets.util.compat.python.past
  • djblets.util.contextmanagers
  • djblets.util.dates
  • djblets.util.decorators
  • djblets.util.filesystem
  • djblets.util.functional
  • djblets.util.html
  • djblets.util.http
  • djblets.util.humanize
  • djblets.util.json_utils
  • djblets.util.properties
  • djblets.util.serializers
  • djblets.util.symbols
  • djblets.util.templatetags.djblets_deco
  • djblets.util.templatetags.djblets_email
  • djblets.util.templatetags.djblets_forms
  • djblets.util.templatetags.djblets_images
  • djblets.util.templatetags.djblets_js
  • djblets.util.templatetags.djblets_utils
  • djblets.util.typing
  • djblets.util.views
  • djblets.views.generic.base
  • djblets.views.generic.etag
  • djblets.webapi.auth
  • djblets.webapi.auth.backends
  • djblets.webapi.auth.backends.api_tokens
  • djblets.webapi.auth.backends.base
  • djblets.webapi.auth.backends.basic
  • djblets.webapi.auth.backends.oauth2_tokens
  • djblets.webapi.auth.views
  • djblets.webapi.decorators
  • djblets.webapi.encoders
  • djblets.webapi.errors
  • djblets.webapi.fields
  • djblets.webapi.managers
  • djblets.webapi.models
  • djblets.webapi.oauth2_scopes
  • djblets.webapi.resources
  • djblets.webapi.resources.base
  • djblets.webapi.resources.group
  • djblets.webapi.resources.registry
  • djblets.webapi.resources.root
  • djblets.webapi.resources.user
  • djblets.webapi.resources.mixins.api_tokens
  • djblets.webapi.resources.mixins.forms
  • djblets.webapi.resources.mixins.oauth2_tokens
  • djblets.webapi.resources.mixins.queries
  • djblets.webapi.responses
  • djblets.webapi.signals
  • djblets.webapi.testing
  • djblets.webapi.testing.decorators
  • djblets.webapi.testing.testcases
  • General Index
  • Python Module Index
  • Release Notes
  • djblets.util.json_utils¶

    exception JSONPatchError(msg, doc, patch, patch_entry_index=None)[source]¶

    Bases: Exception

    An error occurred while patching an object.

    doc¶

    The original JSON document the patch was being applied to. This won’t contain the patched modifications.

    Type:

    dict or list

    patch¶

    The patch being applied. The value depends on the type of patch.

    Type:

    object

    patch_entry_index¶

    The index of the patch being applied. This can be None if the error doesn’t apply to a specific entry.

    Type:

    int, optional

    __init__(msg, doc, patch, patch_entry_index=None)[source]¶

    Initialize the error.

    Parameters:
    • msg (unicode) – The error message.

    • doc (dict or list) – The original JSON document the patch was being applied to. This won’t contain the patched modifications. patch.

    • patch (object) – The patch being applied. The value depends on the patch.

    • patch_entry_index (int, optional) – The index of the patch being applied. This can be None if the error doesn’t apply to a specific entry.

    exception JSONPatchPathError(msg, path, **kwargs)[source]¶

    Bases: JSONPatchError

    Error with a path in a JSON Patch.

    __init__(msg, path, **kwargs)[source]¶

    Initialize the error.

    Parameters:
    • msg (unicode) – The error message describing the path failure.

    • path (unicode) – The path that had an error.

    • **kwargs (dict) – Additional keyword arguments to pass to the parent class.

    __annotations__ = {}¶
    exception JSONPatchAccessError(msg, path, **kwargs)[source]¶

    Bases: JSONPatchPathError

    Access error reading from or writing to part of an object.

    __annotations__ = {}¶
    exception JSONPatchReadAccessError(msg, path, **kwargs)[source]¶

    Bases: JSONPatchAccessError

    Access error reading from part of an object.

    __annotations__ = {}¶
    exception JSONPatchWriteAccessError(msg, path, **kwargs)[source]¶

    Bases: JSONPatchAccessError

    Access error writing to part of an object.

    __annotations__ = {}¶
    exception JSONPatchTestError(msg, path, **kwargs)[source]¶

    Bases: JSONPatchPathError

    Test condition failed when applying a JSON Patch.

    __annotations__ = {}¶
    exception JSONPointerError[source]¶

    Bases: Exception

    Base class for JSON Pointer errors.

    exception JSONPointerSyntaxError[source]¶

    Bases: JSONPointerError

    Syntax error in a JSON Pointer path.

    __annotations__ = {}¶
    exception JSONPointerLookupError(msg, parent, token, token_index, tokens)[source]¶

    Bases: JSONPointerError

    Error looking up data from a JSON Pointer path.

    __init__(msg, parent, token, token_index, tokens)[source]¶

    Initialize the error.

    Parameters:
    • msg (unicode) – The error message.

    • parent (object) – The parent object. This may be a dictionary or a list.

    • token (unicode) – The last resolvable token in the path. This will be None if the first token failed.

    • token_index (int) – The 0-based index of the last resolvable token in the path. This will be None if the first token failed.

    • tokens (list of unicode) – The list of tokens comprising the full path.

    __annotations__ = {}¶
    class JSONPointerEndOfList(json_list)[source]¶

    Bases: object

    A representation of the end of a list.

    This is used by the JSON Pointer functions to represent the very end of a list (not the last item). This is used primarily when specifying an insertion point, with this value repersenting appending to a list.

    __init__(json_list)[source]¶

    Initialize the object.

    Parameters:

    json_list (list) – The list this object represents.

    __eq__(other_list)[source]¶

    Return whether two instances are equal.

    Instances are equal if both of their lists are equal.

    Parameters:

    other_list (JSONPointerEndOfList) – The other instance to compare to for equality.

    Returns:

    True if the two lists are equal.

    Return type:

    bool

    __repr__()[source]¶

    Return a string representation of the instance.

    Returns:

    A string representation of the instance.

    Return type:

    unicode

    __hash__ = None¶
    json_merge_patch(doc, patch, can_write_key_func=None)[source]¶

    Apply a JSON Merge Patch to a value.

    This is an implementation of the proposed JSON Merge Patch standard (RFC 7396), which is a simple algorithm for applying changes to a JSON-compatible data structure.

    This will attempt to merge the contents of the patch object into the doc object as best as possible, using the following rules:

    • If a key in patch matches a key in doc, and the value is None, the key in doc is removed.

    • If a key in patch matches a key in doc, and the value is a dictionary, this method will be called on the values in each and the result will be stored as the new value.

    • If a key in patch matches a key in doc, and the value is not a dictionary, the value from patch will replace the value in doc.

    • If patch is a dictionary but doc is not, then patch will be returned directly.

    • If patch is a dictionary but doc is not, then doc will be discarded and the JSON Merge Patch will be applied to a new empty dictionary.

    • If patch is not a dictionary, then patch will be returned directly.

    Parameters:
    • doc (object) – The JSON-compatible document object the patch is being applied to. This will usually be a dict().

    • patch (object) – The JSON-compatible patch to apply.

    • can_write_key_func (callable, optional) –

      An optional function to call for each key to determine if the key can be written in the new dictionary. This must take the following form:

      def can_write_key(doc, patch, path, **kwargs):
          ...
      

      This must return a boolean indicating if the key can be written, or may raise a JSONPatchError to abort the patching process. If the function returns False, the key will simply be skipped.

    Returns:

    The resulting object. This will be the same type as patch.

    Return type:

    object

    Raises:
    • JSONPatchError – There was an error patching the document. This is only raised by can_write_key_func implementations.

    • ValueError – A provided parameter was incorrect.

    json_patch(doc, patch, can_read_key_func=None, can_write_key_func=None)[source]¶

    Apply a JSON Patch to a value.

    A JSON Patch (RFC 6902), similar to a JSON Merge Patch, is used to make changes to an existing JSON-compatible data structure. JSON Patches are composed of a list of operations which can add a new value, remove a value, replace an existing value, move a value, copy a value, or test that a path has a given value. All operations must pass for a patch to apply.

    A full description of the operations are available in the RFC or from http://jsonpatch.com/.

    Parameters:
    • doc (dict or list) – The root JSON document to apply the patch to. This will not be modified itself.

    • patch (list of dict) – The list of operations to apply to the JSON document.

    • can_read_key_func (callable, optional) –

      An optional function to call for each path to determine if the path can be read from the document. This is in the following form:

      def can_read_key(doc, patch, patch_entry, path, **kwargs):
          ...
      

      It must return a boolean indicating if the key can be written.

    • can_write_key_func (callable, optional) –

      An optional function to call for each path to determine if the path can be written to the document. This takes the same form as can_read_key_func.

      If not provided, it will default to can_read_key_func.

    Returns:

    The resulting JSON document after the patch is applied.

    Return type:

    dict or list

    Raises:

    JSONPatchError – An error occurred patching the JSON document.

    json_get_pointer_info(obj, path)[source]¶

    Return information from a JSON object based on a JSON Pointer path.

    JSON Pointers are a standard way of specifying a path to data within a JSON object. This method takes a JSON Pointer path and returns information from the given object based on that path.

    Pointer paths consist of dictionary keys, array indexes, or a special - token (representing the end of a list, after the last item) separated by / tokens. There are also two special escaped values: ~0, representing a ~ character, and ~1, representing a / character.

    Paths must start with /, or must be an empty string (which will match the provided object). If the path has a trailing /, then the final token is actually an empty string (matching an empty key in a dictionary).

    If the Pointer does not resolve to a complete path (for instance, a key specified in the path is missing), the resulting information will return the keys that could be resolved, keys that could not be resolved, the object where it left off, and an error message. This allows implementations to determine which part of a path does not yet exist, potentially for the purpose of inserting data at that key in the path.

    Parameters:
    • obj (object or list) – The object or list representing the starting object for the path.

    • path (unicode) – The Pointer path for the lookup.

    Returns:

    Information about the object and what the path was able to match. This has the following keys:

    value (object):

    The resulting value from the path, if the path was fully resolved.

    This will be a JSONPointerEndOfList if the last part of the path was a - token (representing the very end of a list).

    tokens (list):

    The normalized (unescaped) list of path tokens that comprise the full path.

    parent (object):

    The parent object for either the most-recently resolved value.

    resolved (list):

    The list of resolved objects from the original JSON object. This will contain each key, array item, or other value that was found, in path order.

    lookup_error (unicode):

    The error message, if any, if failing to resolve the full path.

    Return type:

    dict

    Raises:

    JSONPointerSyntaxError – There was a syntax error with a token in the path.

    json_resolve_pointer(obj, path)[source]¶

    Return the value from a JSON object based on a JSON Pointer path.

    See json_get_pointer_info() for information on how a Pointer path is constructed. Unlike that function, this requires a fully-resolved path.

    Parameters:
    • obj (object or list) – The object or list representing the starting object for the path.

    • path (unicode) – The Pointer path for the lookup.

    Returns:

    The resulting value from the object, based on the path.

    This will be a JSONPointerEndOfList if the last part of the path was a - token (representing the very end of a list).

    Return type:

    object

    Raises:
    • JSONPointerLookupError – The path could not be fully resolved.

    • JSONPointerSyntaxError – There was a syntax error with a token in the path.

    Keep up with the latest Review Board releases, security updates, and helpful information.

    About
    News
    Demo
    RBCommons Hosting
    Integrations
    Happy Users
    Support Options
    Documentation
    FAQ
    User Manual
    RBTools
    Administration Guide
    Power Pack
    Release Notes
    Downloads
    Review Board
    RBTools
    Djblets
    Power Pack
    Package Store
    PGP Signatures
    Contributing
    Bug Tracker
    Submit Patches
    Development Setup
    Wiki
    Follow Us
    Mailing Lists
    Reddit
    Twitter
    Mastodon
    Facebook
    YouTube

    Copyright © 2006-2025 Beanbag, Inc. All rights reserved.

    Terms of Service — Privacy Policy — AI Ethics Policy — Branding

    On this page

    • [Top]
    • JSONPatchError
      • JSONPatchError.doc
      • JSONPatchError.patch
      • JSONPatchError.patch_entry_index
      • JSONPatchError.__init__()
    • JSONPatchPathError
      • JSONPatchPathError.__init__()
      • JSONPatchPathError.__annotations__
    • JSONPatchAccessError
      • JSONPatchAccessError.__annotations__
    • JSONPatchReadAccessError
      • JSONPatchReadAccessError.__annotations__
    • JSONPatchWriteAccessError
      • JSONPatchWriteAccessError.__annotations__
    • JSONPatchTestError
      • JSONPatchTestError.__annotations__
    • JSONPointerError
    • JSONPointerSyntaxError
      • JSONPointerSyntaxError.__annotations__
    • JSONPointerLookupError
      • JSONPointerLookupError.__init__()
      • JSONPointerLookupError.__annotations__
    • JSONPointerEndOfList
      • JSONPointerEndOfList.__init__()
      • JSONPointerEndOfList.__eq__()
      • JSONPointerEndOfList.__repr__()
      • JSONPointerEndOfList.__hash__
    • json_merge_patch()
    • json_patch()
    • json_get_pointer_info()
    • json_resolve_pointer()