The problem with code from @jessepearson was that deleted fields weren’t removed. Fields which were changed or added were handled correctly.
At the moment I’m using a plugin named Advanced Custom Fields: Auto JSON Sync, which handles all situations fine. You can find it here: https://github.com/jawittdesigns/advanced-custom-fields-auto-json-sync/