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

Carsten Bormann <cabo@tzi.org> Thu, 30 October 2014 11:37 UTC

Return-Path: <cabo@tzi.org>
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 301831AD0C0 for <json@ietfa.amsl.com>; Thu, 30 Oct 2014 04:37:21 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.55
X-Spam-Level:
X-Spam-Status: No, score=-1.55 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, HELO_EQ_DE=0.35] autolearn=no
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 qU5yHVOvYnW9 for <json@ietfa.amsl.com>; Thu, 30 Oct 2014 04:37:19 -0700 (PDT)
Received: from mailhost.informatik.uni-bremen.de (mailhost.informatik.uni-bremen.de [IPv6:2001:638:708:30c9::12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 0450E1AD0CD for <json@ietf.org>; Thu, 30 Oct 2014 04:37:18 -0700 (PDT)
X-Virus-Scanned: amavisd-new at informatik.uni-bremen.de
Received: from smtp-fb3.informatik.uni-bremen.de (smtp-fb3.informatik.uni-bremen.de [134.102.224.120]) by mailhost.informatik.uni-bremen.de (8.14.5/8.14.5) with ESMTP id s9UBbEfg007200; Thu, 30 Oct 2014 12:37:14 +0100 (CET)
Received: from eduroam-pool7-0325.wlan.uni-bremen.de (eduroam-pool7-0325.wlan.uni-bremen.de [134.102.113.69]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-fb3.informatik.uni-bremen.de (Postfix) with ESMTPSA id 5B23A9DC; Thu, 30 Oct 2014 12:37:14 +0100 (CET)
Content-Type: text/plain; charset="utf-8"
Mime-Version: 1.0 (Mac OS X Mail 8.0 \(1990.1\))
From: Carsten Bormann <cabo@tzi.org>
In-Reply-To: <CALcybBBHVApdaTw15p74XjHY-_z0+q83Zptw7zrd5mytb2B-ug@mail.gmail.com>
Date: Thu, 30 Oct 2014 12:37:13 +0100
X-Mao-Original-Outgoing-Id: 436361833.186377-485c81975418bf267514844c1be574d5
Content-Transfer-Encoding: quoted-printable
Message-Id: <723AD00E-4935-4B59-B692-370F2D887E27@tzi.org>
References: <CALcybBBHVApdaTw15p74XjHY-_z0+q83Zptw7zrd5mytb2B-ug@mail.gmail.com>
To: Francis Galiegue <fgaliegue@gmail.com>
X-Mailer: Apple Mail (2.1990.1)
Archived-At: http://mailarchive.ietf.org/arch/msg/json/YydUxKeYyV1a0qpxG5bO0kFmn9g
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 11:37:21 -0000

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

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.

Grüße, Carsten