JSON Patch: The Smart Way to Update Your API Data

Learn what JSON Patch is, how it works, and why it's efficient for updating APIs, and how Apidog helps you test and debug JSON Patch API.

INEZA Felin-Michel

INEZA Felin-Michel

1 September 2025

JSON Patch: The Smart Way to Update Your API Data

You've built a modern API. The GET fetches data, the POST creates new resources—smooth so far. But when it comes to updating data, things get tricky.

Say a user just wants to change their email. Do you really need them to resend the entire user profile? That's clunky, inefficient, and error-prone—especially with slow connections or conflicting updates.

There's a better way: JSON Patch.
Instead of sending the whole object, you send only the changes. Think of it like giving a tailor a list of alterations rather than remaking the whole suit.

Since JSON has become the universal language for APIs, JSON Patch offers a lightweight, elegant solution for partial updates.

Of course, designing and testing APIs with JSON Patch requires the right tools. That's where Apidog comes in. It lets you craft, test, and validate JSON Patch requests with ease—so you know your updates work as intended before writing a single line of code. Best of all, it's free to download and start experimenting with today.

💡
Want a great API Testing tool that generates beautiful API Documentation?

Want an integrated, All-in-One platform for your Developer Team to work together with maximum productivity?

Apidog delivers all your demands, and replaces Postman at a much more affordable price!
button

Next, let's break down what JSON Patch is, how it works, and why it should be part of your next project.

The Problem: The "Blind" PUT Request

To understand why JSON Patch is so useful, we first need to understand the problem it solves. Traditionally, updating a resource in a RESTful API is done with the PUT HTTP method.

A PUT request is meant to be idempotent (making the same request multiple times has the same effect as making it once) and it typically replaces the entire resource at the target URL with the new representation provided in the request body.

Let's imagine a user profile resource:

GET /users/123

{
  "id": 123,
  "username": "johndoe",
  "email": "john.old@example.com",
  "firstName": "John",
  "lastName": "Doe",
  "age": 30,
  "accountStatus": "active",
  "preferences": {
    "theme": "light",
    "notifications": true
  },
  "signUpDate": "2023-01-15"
}

Now, if John just wants to change his email address, a typical PUT request would look like this:

PUT /users/123

{
  "id": 123,
  "username": "johndoe",
  "email": "john.new@example.com", // The changed field
  "firstName": "John",
  "lastName": "Doe",
  "age": 30,
  "accountStatus": "active",
  "preferences": {
    "theme": "light",
    "notifications": true
  },
  "signUpDate": "2023-01-15"
}

Do you see the issue? We had to send back every single field, even though 99% of the data didn't change. This approach has several downsides:

  1. Increased Bandwidth: We're sending a lot of unnecessary data over the wire. For large resources, this can be a significant performance hit, especially on mobile networks.
  2. Higher Risk of Conflicts: If another process updates the age field while John is editing his email, John's PUT request could accidentally overwrite that new age with the old value he sent.
  3. Complexity for the Client: The client application must first GET the entire resource, modify the specific field, and then PUT the whole thing back. It's multiple steps and requires the client to manage the entire state.

This is where the HTTP PATCH method comes to the rescue.

The Solution: Introducing HTTP PATCH and JSON Patch

The HTTP PATCH method was introduced to allow for partial modifications to a resource. Unlike PUT, which replaces the entire resource, PATCH applies a set of changes to the resource.

But there's a catch: the HTTP standard doesn't define what the format of those "changes" should be. You could invent your own. You could send something like:

{ "op": "change_email", "value": "new@example.com" }

But this would be custom, non-standard, and other developers would have to learn your specific language.

This is the gap that JSON Patch fills. JSON Patch (defined in RFC 6902) is a standardized format for specifying changes to be applied to a JSON document. It provides a clear, unambiguous language for describing exactly how a JSON document should be modified.

When you combine the HTTP PATCH method with a body formatted as a JSON Patch document, you have a powerful, standards-based way to perform partial updates.

How JSON Patch Works: The Basics

A JSON Patch document is always a JSON array. Each element in the array is an operation object. These operations are applied to the target document in order, and the entire patch is atomic, meaning if any single operation fails, the entire patch aborts, and the document is left unchanged.

Every operation object has a mandatory op member (short for "operation") that specifies the action to perform. The most common operations are add, remove, replace, move, and copy.

Let's look at the previous example of John changing his email. Using JSON Patch, the request becomes dramatically simpler:

PATCH /users/123

[
  { "op": "replace", "path": "/email", "value": "john.new@example.com" }
]

That's it! We're sending a single operation: "replace the value at the path '/email' with this new value." The request is small, clear, and intent-driven. We don't touch any other field.

Understanding the path Property

The path property is a JSON Pointer (RFC 6901), a string that uses a slash-based syntax to navigate through the JSON document to the specific value you want to manipulate.

This syntax is powerful for navigating nested JSON structures.

JSON Patch vs JSON Merge Patch

Developers often confuse JSON Patch (RFC 6902) with JSON Merge Patch (RFC 7386). Let’s clarify.

JSON Patch:

JSON Merge Patch:

In short:

The JSON Patch Operations

Let's break down the most common operations with examples. We'll use the same user profile as our target document.

1. The add Operation

The add operation is used to insert a new value into an object or array.

Add a new property to an object:

{ "op": "add", "path": "/twitterHandle", "value": "@johndoe" }

This adds a new twitterHandle field to the user object.

Add an element to an array (at a specific index):

Imagine the user has a "hobbies" array: ["reading", "cycling"].

{ "op": "add", "path": "/hobbies/1", "value": "hiking" }

This inserts "hiking" at index 1, resulting in ["reading", "hiking", "cycling"]. To add to the end of the array, you can use /-: { "op": "add", "path": "/hobbies/-", "value": "hiking" }.

2. The remove Operation

The remove operation deletes a value at a specified location.

Remove a property from an object:

{ "op": "remove", "path": "/age" }

This removes the entire age field from the user object.

Remove an element from an array:

{ "op": "remove", "path": "/hobbies/0" }

This removes the first element (index 0) from the hobbies array.

3. The replace Operation

The replace operation is essentially a combination of remove and add at the same path. It replaces the existing value at a location with a new value. Our email example was a classic replace.

Change a user's theme preference:

{ "op": "replace", "path": "/preferences/theme", "value": "dark" }

4. The move Operation

The move operation removes a value from one location and adds it to another.

Move a value from one property to another:

{ "op": "move", "from": "/firstName", "path": "/first_name" }

This would move the value of firstName to a new property called first_name and remove the old firstName property.

5. The copy Operation

The copy operation copies a value from one location to another. The original value remains unchanged.

Create a backup of a setting:

{ "op": "copy", "from": "/preferences/theme", "path": "/backupTheme" }

This copies the current theme value to a new backupTheme field.

6. The test Operation

This is a safety feature. The test operation checks that a value at a location is equal to a specified value. If the test fails, the entire patch aborts. This is incredibly useful for preventing conflicts (optimistic locking).

Ensure no one else has changed the email before updating it:

[
  { "op": "test", "path": "/email", "value": "john.old@example.com" },
  { "op": "replace", "path": "/email", "value": "john.new@example.com" }
]

If the current email is not "john.old@example.com" (perhaps another process already changed it), the test operation fails, and the replace never happens. This ensures your update is based on the latest known state.

Why Use JSON Patch? The Benefits

  1. Efficiency: The most obvious benefit. You only send the changes, significantly reducing payload size and improving performance.
  2. Concurrency Control: The test operation provides a built-in mechanism for optimistic locking, helping you avoid lost updates and race conditions.
  3. Atomicity: The all-or-nothing nature of a patch application ensures your data remains consistent. If the fifth operation in a ten-operation patch fails, the first four are rolled back.
  4. Clarity and Intent: The request body clearly describes the intent of the change ("replace the email", "add a hobby") rather than just dumping a new state. This makes logs more readable and debugging easier.
  5. Standardization: It's an IETF standard (RFC 6902). Other developers will recognize it, and many libraries and frameworks across different programming languages have built-in support for parsing and applying JSON Patch documents.

Common Pitfalls and Mistakes with JSON Patch

Even though JSON Patch is powerful, developers often run into these issues:

Why APIs Use JSON Patch

APIs love JSON Patch because it’s:

For example, GitHub’s API supports JSON Patch for editing repository metadata efficiently.

JSON Patch in REST APIs

In RESTful APIs, JSON Patch is often used with the HTTP PATCH method.

PATCH vs PUT:

With JSON Patch, the Content-Type is:

application/json-patch+json

This tells the server the body contains a JSON Patch document.

JSON Patch in GraphQL and Other Protocols

While JSON Patch is primarily used in REST APIs, it also has relevance in:

How JSON Patch Improves Efficiency

Imagine a mobile app syncing user profiles. Instead of re-uploading a 2MB JSON file for every tiny update, the app can just send a small patch request.

This means:

Challenges and Considerations

JSON Patch is powerful, but it's not without its complexities.

  1. Complex Implementation on the Server: Applying a patch correctly on the server is more complex than simply accepting a new JSON object. You need to validate each operation, handle pointers to non-existent paths appropriately, and ensure the entire sequence is applied atomically. Luckily, most modern web frameworks have libraries to handle this for you (e.g., json-patch for Node.js, jsonpatch for Python, JsonPatchDocument in .NET).
  2. Potential for Errors: A malformed patch document or an invalid pointer (e.g., trying to replace a field that doesn't exist) will result in an error. Your API must handle these gracefully and return clear error messages (usually a 422 Unprocessable Entity or 400 Bad Request).
  3. Not a Silver Bullet: For very simple resources, a PUT might still be simpler. JSON Patch shines when your resources are large or when you need to support complex, conditional updates.

Testing JSON Patch Endpoint with Apidog

Testing JSON Patch manually can be frustrating. This is where a sophisticated API tool becomes invaluable. Apidog, an all-in-one API development platform, can be a great saver here:

button

Example workflow in Apidog:

  1. Create a new request.
  2. Set method to PATCH.
  3. Add Content-Type: application/json-patch+json.
  4. Enter your JSON Patch array.
  5. Send and verify results instantly.

By using Apidog, you move from guessing if your patch is correct to knowing it's built right, allowing you to confidently implement and consume JSON Patch APIs and start testing JSON Patch like a pro.

JSON Patch Best Practices

To use JSON Patch effectively:

  1. Validate your JSON Patch documents before sending.
  2. Use test operations when consistency matters.
  3. Keep patches small for efficiency.
  4. Document your API clearly when using JSON Patch.
  5. Use tools like Apidog to streamline testing.

Conclusion: Embracing a More Efficient API Standard

So, what is JSON Patch?

It’s a standardized way to describe changes to JSON documents using operations like add, remove, and replace. Instead of sending full objects, you can send only the changes making your APIs more efficient, reliable, and flexible.

JSON Patch transforms the way we think about updating data over APIs. It moves us from the blunt instrument of full-document replacement to the precision of surgical changes. By embracing this standard, we build APIs that are more efficient, less prone to conflicts, and clearer in their intent.

While it requires a bit more upfront thought on the server side, the benefits for client applications and network performance are substantial. The next time you find yourself designing an update endpoint, resist the default PUT and ask yourself: "Could this be a job for PATCH?"

For developers, understanding JSON Patch is key to working with modern APIs, especially when handling partial updates. And with tools like Apidog, you can test, validate, and debug JSON Patch requests with ease.

button

Explore more

502 Bad Gateway: What Is This HTTP Status Code?

502 Bad Gateway: What Is This HTTP Status Code?

The 502 response code occurs when a gateway server gets an invalid response from an upstream server. Learn how Apidog helps prevent 502 errors.

1 September 2025

Apidog vs Bruno: Which API Client Should You Choose in 2025?

Apidog vs Bruno: Which API Client Should You Choose in 2025?

Compare Apidog and Bruno API clients in this comprehensive technical analysis. Discover key differences in features, collaboration tools, version control, and performance to choose the right API testing solution for your development workflow.

1 September 2025

What Is a JSON Path Finder?

What Is a JSON Path Finder?

In the rapidly evolving API world, JSONPath Finder helps you navigate and extract data from complex JSON fast. This guide explains JSONPath, how it works, key syntax, practical examples, and how JSONPath in Apidog supercharges API development, testing, and debugging.

29 August 2025

Practice API Design-first in Apidog

Discover an easier way to build and use APIs