MCPcopy Index your code
hub / github.com/DaveGamble/cJSON / compare_json

Function compare_json

cJSON_Utils.c:604–690  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

602}
603
604static cJSON_bool compare_json(cJSON *a, cJSON *b, const cJSON_bool case_sensitive)
605{
606 if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)))
607 {
608 /* mismatched type. */
609 return false;
610 }
611 switch (a->type & 0xFF)
612 {
613 case cJSON_Number:
614 /* numeric mismatch. */
615 if ((a->valueint != b->valueint) || (!compare_double(a->valuedouble, b->valuedouble)))
616 {
617 return false;
618 }
619 else
620 {
621 return true;
622 }
623
624 case cJSON_String:
625 /* string mismatch. */
626 if (strcmp(a->valuestring, b->valuestring) != 0)
627 {
628 return false;
629 }
630 else
631 {
632 return true;
633 }
634
635 case cJSON_Array:
636 for ((void)(a = a->child), b = b->child; (a != NULL) && (b != NULL); (void)(a = a->next), b = b->next)
637 {
638 cJSON_bool identical = compare_json(a, b, case_sensitive);
639 if (!identical)
640 {
641 return false;
642 }
643 }
644
645 /* array size mismatch? (one of both children is not NULL) */
646 if ((a != NULL) || (b != NULL))
647 {
648 return false;
649 }
650 else
651 {
652 return true;
653 }
654
655 case cJSON_Object:
656 sort_object(a, case_sensitive);
657 sort_object(b, case_sensitive);
658 for ((void)(a = a->child), b = b->child; (a != NULL) && (b != NULL); (void)(a = a->next), b = b->next)
659 {
660 cJSON_bool identical = false;
661 /* compare object keys */

Callers 2

apply_patchFunction · 0.85
generate_merge_patchFunction · 0.85

Calls 3

sort_objectFunction · 0.85
compare_stringsFunction · 0.85
compare_doubleFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…