Files
json-c/json_patch.h
Alexandru Ardelean 538b046884 json_patch: add first implementation only with patch application
Initially I wanted to also do a function that generates the JSON patch from
two JSON documents, but even just applying the JSON patch was a bit of
work, especially when needing to satisfy all the test-cases.

This change defines all the operation in the RFC6902. The addition isn't
too big (for the json_patch_apply() function), as part of the heavy lifting
is also done by JSON pointer logic.

All the ops were tested with the test-cases defined at:
  https://github.com/json-patch/json-patch-tests

RFC6902: https://tools.ietf.org/html/rfc6902

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
2023-07-31 22:18:01 -04:00

47 lines
1.2 KiB
C

/*
* Copyright (c) 2021 Alexadru Ardelean.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See COPYING for details.
*
*/
/**
* @file
* @brief JSON Patch (RFC 6902) implementation for manipulating JSON objects
*/
#ifndef _json_patch_h_
#define _json_patch_h_
#include "json_pointer.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Apply the JSON patch to the base object.
* The patch object must be formatted as per RFC 6902.
* If the patch is not correctly formatted, an error will
* be returned.
*
* The original `base` object will first be copied, and then
* the patch will be applied.
* If anything fails during patching, the `res` object will be
* NULL and the function will return a negative result.
*
* @param base the JSON object which to patch
* @param patch the JSON object that describes the patch to be applied
* @param the resulting patched JSON object
*
* @return negative if an error (or not found), or 0 if succeeded
*/
JSON_EXPORT int json_patch_apply(struct json_object *base, struct json_object *patch,
struct json_object **res);
#ifdef __cplusplus
}
#endif
#endif