cJSON_Utils.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "cJSON.h"
  2. /* Implement RFC6901 (https://tools.ietf.org/html/rfc6901) JSON Pointer spec. */
  3. cJSON *cJSONUtils_GetPointer(cJSON *object, const char *pointer);
  4. /* Implement RFC6902 (https://tools.ietf.org/html/rfc6902) JSON Patch spec. */
  5. cJSON* cJSONUtils_GeneratePatches(cJSON *from, cJSON *to);
  6. /* Utility for generating patch array entries. */
  7. void cJSONUtils_AddPatchToArray(cJSON *array, const char *op, const char *path, cJSON *val);
  8. /* Returns 0 for success. */
  9. int cJSONUtils_ApplyPatches(cJSON *object, cJSON *patches);
  10. /*
  11. // Note that ApplyPatches is NOT atomic on failure. To implement an atomic ApplyPatches, use:
  12. //int cJSONUtils_AtomicApplyPatches(cJSON **object, cJSON *patches)
  13. //{
  14. // cJSON *modme = cJSON_Duplicate(*object, 1);
  15. // int error = cJSONUtils_ApplyPatches(modme, patches);
  16. // if (!error)
  17. // {
  18. // cJSON_Delete(*object);
  19. // *object = modme;
  20. // }
  21. // else
  22. // {
  23. // cJSON_Delete(modme);
  24. // }
  25. //
  26. // return error;
  27. //}
  28. // Code not added to library since this strategy is a LOT slower.
  29. */
  30. /* Implement RFC7386 (https://tools.ietf.org/html/rfc7396) JSON Merge Patch spec. */
  31. /* target will be modified by patch. return value is new ptr for target. */
  32. cJSON* cJSONUtils_MergePatch(cJSON *target, cJSON *patch);
  33. /* generates a patch to move from -> to */
  34. cJSON *cJSONUtils_GenerateMergePatch(cJSON *from, cJSON *to);
  35. /* Given a root object and a target object, construct a pointer from one to the other. */
  36. char *cJSONUtils_FindPointerFromObjectTo(cJSON *object, cJSON *target);
  37. /* Sorts the members of the object into alphabetical order. */
  38. void cJSONUtils_SortObject(cJSON *object);