json-c  0.17
Data Structures | Functions
json_patch.h File Reference

JSON Patch (RFC 6902) implementation for manipulating JSON objects. More...

Data Structures

struct  json_patch_error
 

Functions

JSON_EXPORT int json_patch_apply (struct json_object *copy_from, struct json_object *patch, struct json_object **base, struct json_patch_error *patch_error)
 

Detailed Description

JSON Patch (RFC 6902) implementation for manipulating JSON objects.

Function Documentation

JSON_EXPORT int json_patch_apply ( struct json_object copy_from,
struct json_object patch,
struct json_object **  base,
struct json_patch_error patch_error 
)

Apply the JSON patch to the base object. The patch object must be formatted as per RFC 6902, i.e. a json_type_array containing patch operations. If the patch is not correctly formatted, an error will be returned.

The json_object at *base will be modified in place. Exactly one of *base or copy_from must be non-NULL. If *base is NULL, a new copy of copy_from will allocated and populated using json_object_deep_copy(). In this case json_object_put() must be used to free *base even if the overall patching operation fails.

If anything fails during patching a negative value will be returned, and patch_error (if non-NULL) will be populated with error details.

Parameters
basea pointer to the JSON object which to patch
patchthe JSON object that describes the patch to be applied
copy_froma JSON object to copy to *base
patch_erroroptional, details about errors
Returns
negative if an error (or not found), or 0 if patch completely applied