DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Join us tomorrow at 1 PM EST: "3-Step Approach to Comprehensive Runtime Application Security"
Save your seat
  1. DZone
  2. Coding
  3. Languages
  4. JavaScript Object Notation (JSON) Patch

JavaScript Object Notation (JSON) Patch

Discover JSON Patch, a great way to relay what you need to know from an API regarding only what has changed so you're not sending all the details over the pipes.

Kin Lane user avatar by
Kin Lane
·
Dec. 26, 17 · News
Like (6)
Save
Tweet
Share
7.18K Views

Join the DZone community and get the full member experience.

Join For Free

I’m continuing my studying into what my new partner in crime Streamdata.io does, and part of this research is understanding the details of their technology stack. Today’s work involves understanding their usage of JavaScript Object Notation (JSON) Patch. When you proxy any existing web API using Streamdata.io, the first thing you get back is a complete JSON representation of the response. But then, with each change, you just get back a JSON Patch response with only the details of what has changed. JSON Patch is used for expressing a sequence of operations to apply to any JSON object or document you’ll find used with the HTTP PATCH method.

The introduction for JSON Patch from RFC [RFC4627] describes it this way:

JavaScript Object Notation (JSON) [RFC4627] is a common format for the exchange and storage of structured data. HTTP PATCH [RFC5789] extends the Hypertext Transfer Protocol (HTTP) [RFC2616] with a method to perform partial modifications to resources. JSON Patch is a format (identified by the media type “application/json-patch+json”) for expressing a sequence of operations to apply to a target JSON document; it is suitable for use with the HTTP PATCH method. This format is also potentially useful in other cases in which it is necessary to make partial updates to a JSON document or to a data structure that has similar constraints (i.e., they can be serialized as an object or an array using the JSON grammar).

JSON Patch is an efficient way to only get the details from an API regarding only what has changed, instead of sending everything over the pipes each time. It makes sense that Streamdata.io has used it in conjunction with Server-Sent Events (SSE) to efficiently cache and stream data from existing web APIs. I have to admit, I never put this together with the PATCH method for API responses. Most of the APIs I’ve seen that use PATCH do not actually implement JSON PATCH, so this was a learning moment for me — something I’m always thankful for, constantly reminding me just how much I do not know in the space, even with my experience studying APIs.

Next, I’m going to invest more time understanding how to write code that navigates and applies JSON Patch in real-world situations. I’ve got my handful of Streamdata.io-enabled APIs streaming me data, but I don’t have the experience applying the changes to a UI or existing system integration as the data flows in. It all makes a lot more sense to me now and provides me with an efficient model for managing changes that occur across APIs. It is also yet ANOTHER reminder for me of how important it is that I study up on RFCs and be knowledgeable regarding existing patterns like this so that I’m not reinventing the wheel when it comes to my API design.

JSON Patch (computing) Object (computer science) JavaScript

Published at DZone with permission of Kin Lane, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How to Submit a Post to DZone
  • Microservices Discovery With Eureka
  • API Design Patterns Review
  • Deploying Java Serverless Functions as AWS Lambda

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: