{"id":13447562,"url":"https://github.com/npm/parse-conflict-json","last_synced_at":"2025-05-16T06:06:13.491Z","repository":{"id":35055597,"uuid":"201119129","full_name":"npm/parse-conflict-json","owner":"npm","description":"Parse a JSON string that has git merge conflicts, resolving if possible","archived":false,"fork":false,"pushed_at":"2025-04-28T18:56:31.000Z","size":250,"stargazers_count":34,"open_issues_count":4,"forks_count":4,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-05-14T20:57:24.167Z","etag":null,"topics":["npm-cli"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/npm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-07T19:58:21.000Z","updated_at":"2025-04-28T18:56:34.000Z","dependencies_parsed_at":"2024-04-20T22:56:24.309Z","dependency_job_id":"6b9a0b54-a541-46a3-b7a5-faaad8dfe0fc","html_url":"https://github.com/npm/parse-conflict-json","commit_stats":{"total_commits":60,"total_committers":5,"mean_commits":12.0,"dds":0.6833333333333333,"last_synced_commit":"d583e92525647d6f3dd55d51b0a8975759c6a0c3"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Fparse-conflict-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Fparse-conflict-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Fparse-conflict-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Fparse-conflict-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/npm","download_url":"https://codeload.github.com/npm/parse-conflict-json/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254478189,"owners_count":22077676,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["npm-cli"],"created_at":"2024-07-31T05:01:21.011Z","updated_at":"2025-05-16T06:06:08.470Z","avatar_url":"https://github.com/npm.png","language":"JavaScript","readme":"# parse-conflict-json\n\nParse a JSON string that has git merge conflicts, resolving if possible.\n\nIf the JSON is valid, it just does `JSON.parse` as normal.\n\nIf either side of the conflict is invalid JSON, then an error is thrown for\nthat.\n\n## USAGE\n\n```js\n// after a git merge that left some conflicts there\nconst data = fs.readFileSync('package-lock.json', 'utf8')\n\n// reviverFunction is passed to JSON.parse as the reviver function\n// preference defaults to 'ours', set to 'theirs' to prefer the other\n// side's changes.\nconst parsed = parseConflictJson(data, reviverFunction, preference)\n\n// returns true if the data looks like a conflicted diff file\nparsed.isDiff(data)\n```\n\n## Algorithm\n\nIf `prefer` is set to `theirs`, then the vaules of `theirs` and `ours` are\nswitched in the resolver function.  (Ie, we'll apply their changes on top\nof our object, rather than the other way around.)\n\n- Parse the conflicted file into 3 pieces: `ours`, `theirs`, and `parent`\n\n- Get the [diff](https://github.com/angus-c/just#just-diff) from `parent`\n  to `ours`.\n\n- [Apply](https://github.com/angus-c/just#just-diff-apply) each change of\n  that diff to `theirs`.\n\n    If any change in the diff set cannot be applied (ie, because they\n    changed an object into a non-object and we changed a field on that\n    object), then replace the object at the specified path with the object\n    at the path in `ours`.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm%2Fparse-conflict-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnpm%2Fparse-conflict-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm%2Fparse-conflict-json/lists"}