Skip to content

Support JSON Merge Patch (application/merge-patch+json) #231

@melvincarvalho

Description

@melvincarvalho

Summary

Add support for JSON Merge Patch (RFC 7396) as a PATCH content type for JSON-LD resources.

Motivation

Currently JSS supports N3 Patch and SPARQL Update for PATCH operations, which are RDF-centric and verbose for simple field updates. JSON Merge Patch is a natural fit for JSON-LD resources:

PATCH /profile/card.jsonld
Content-Type: application/merge-patch+json

{"foaf:name": "New Name", "foaf:nick": "newnick"}

This merges the patch into the existing JSON-LD, updating only the specified fields.

Spec

  • RFC 7396 — JSON Merge Patch
  • Null values remove keys: {"foaf:nick": null} deletes the field
  • Nested objects merge recursively
  • Arrays are replaced, not merged

Implementation

In the PATCH handler (src/handlers/resource.js):

  1. Check Content-Type: application/merge-patch+json
  2. Read existing resource as JSON
  3. Apply merge patch (recursive merge, ~10 lines)
  4. Write back

Use cases

  • Profile editing (update name, add links)
  • Any JSON-LD resource field update
  • Simpler alternative to N3 Patch for JSON-native clients

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions