Re: [Json] RFC 7386: correct indentation of the MergePatch function...

Francis Galiegue <fgaliegue@gmail.com> Thu, 30 October 2014 12:18 UTC

Return-Path: <fgaliegue@gmail.com>
X-Original-To: json@ietfa.amsl.com
Delivered-To: json@ietfa.amsl.com
Received: from localhost (ietfa.amsl.com [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 0067A1A002A for <json@ietfa.amsl.com>; Thu, 30 Oct 2014 05:18:57 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2
X-Spam-Level:
X-Spam-Status: No, score=-2 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, SPF_PASS=-0.001] autolearn=ham
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wS16VZnPV33l for <json@ietfa.amsl.com>; Thu, 30 Oct 2014 05:18:55 -0700 (PDT)
Received: from mail-pa0-x230.google.com (mail-pa0-x230.google.com [IPv6:2607:f8b0:400e:c03::230]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 185F11A0040 for <json@ietf.org>; Thu, 30 Oct 2014 05:18:55 -0700 (PDT)
Received: by mail-pa0-f48.google.com with SMTP id ey11so5340752pad.35 for <json@ietf.org>; Thu, 30 Oct 2014 05:18:54 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=EtGh22257oZag293qDu4D+pVK5pEHTk0CUAHS/vSmY0=; b=lh01IREHJTafqdnZahat/l5bv7aslV2Go8poEesFTCJOe1JWxqz255KDcTg1QGUIzQ 6MST1S+TLwuWqQECkECyyNkaeBQBiSEYmjcQdvkjtodE4DxS5ruT5AAS98UnNWDvjGZ7 fEG3tNdZPzLxku6K816IdRWaMOe907QgOTJ2Hm5A35NuZI6OnEWF6MxAi17QjZZp9j8L NxnLtccw2ZOONU+FxHk+r8W45JXGtZdYtPEmPBpYlau2tfgbrTV8ftZM1bC0SNKObPCd icK15Wd+yi/eAGlaeD/nJ2R2hnsLNFLazRj/KVYAdX/MpOlY1nVtn8N08mluqBenND/L tvfg==
MIME-Version: 1.0
X-Received: by 10.68.57.200 with SMTP id k8mr802510pbq.96.1414671534707; Thu, 30 Oct 2014 05:18:54 -0700 (PDT)
Received: by 10.70.32.165 with HTTP; Thu, 30 Oct 2014 05:18:54 -0700 (PDT)
In-Reply-To: <723AD00E-4935-4B59-B692-370F2D887E27@tzi.org>
References: <CALcybBBHVApdaTw15p74XjHY-_z0+q83Zptw7zrd5mytb2B-ug@mail.gmail.com> <723AD00E-4935-4B59-B692-370F2D887E27@tzi.org>
Date: Thu, 30 Oct 2014 13:18:54 +0100
Message-ID: <CALcybBCQDbO5QHABf-2so_3TJjDa9M5Db0Uc_DKnpVisC9poeg@mail.gmail.com>
From: Francis Galiegue <fgaliegue@gmail.com>
To: Carsten Bormann <cabo@tzi.org>
Content-Type: text/plain; charset="UTF-8"
Archived-At: http://mailarchive.ietf.org/arch/msg/json/_wIoUgUcmyyG_E2CsdWd31wuxNY
Cc: json@ietf.org
Subject: Re: [Json] RFC 7386: correct indentation of the MergePatch function...
X-BeenThere: json@ietf.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: "JavaScript Object Notation \(JSON\) WG mailing list" <json.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/json>, <mailto:json-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/json/>
List-Post: <mailto:json@ietf.org>
List-Help: <mailto:json-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/json>, <mailto:json-request@ietf.org?subject=subscribe>
X-List-Received-Date: Thu, 30 Oct 2014 12:18:57 -0000

On Thu, Oct 30, 2014 at 12:37 PM, Carsten Bormann <cabo@tzi.org> wrote:
> On 30 Oct 2014, at 12:29, Francis Galiegue <fgaliegue@gmail.com> wrote:
>>
>>            if Value is null:
>>              if Name exists in Target:
>>                remove the Name/Value pair from Target
>>              else:
>>                Target[Name] = MergePatch(Target[Name], Value)
>
> Unfortunately, not quite.
>
> http://tools.ietf.org/html/draft-ietf-appsawg-json-merge-patch-07
>
> says:
>
>    define MergePatch(Target, Patch):
>      if Patch is an Object:
>        if Target is not an Object:
>          Target = {} # Ignore the contents and set it to an empty Object
>        for each Name/Value pair in Patch:
>          if Value is null:
>            if Name exists in Target:
>              remove the Name/Value pair from Target
>          else:
>            Target[Name] = MergePatch(Target[Name], Value)
>        return Target
>      else:
>        return Patch
>

Wee! Glad I asked, then... I'd have made a fundamental implementation mistake.

> You can also look at
>
> https://gist.github.com/cabo/7888768#file-merge-patch-rb
>
> which is the same thing in a language that is not indentation-sensitive.
>

Thanks for the pointer!

Regards,
-- 
Francis Galiegue, fgaliegue@gmail.com, https://github.com/fge
JSON Schema in Java: http://json-schema-validator.herokuapp.com
Parsers in pure Java: https://github.com/parboiled1/grappa (redde
Caesaris: https://github.com/sirthias)