Subject: bug#21798: 25.0.50; [PATCH] Add support for retrieving paths to JSON elements

From: Simen Heggestøyl <[email-masked]>
Date: Fri, 06 Nov 2015 17:31:28 +0100

Hello Dmitry, thanks for the feedback.

On Tue, Nov 3, 2015 at 3:00 AM, Dmitry Gutov <[email-masked]> wrote:
> I have to say, I'm still not very comfortable with mixing it sort of 
> alien logic inside json-read-object and json-read-array (would anyone 
> else like to chime in with their opinion?).

I understand your uneasiness, I feel the same way after you pointed it
out.

> Here's an idea: both json-read-object-1 and json-read-array-2 will 
> advise json-read to add the new logic around calls to it (there will 
> have to be some guard in the advice, so that recursive calls are run 
> unmodified).

I'm reluctant to use advises for it, not based on my own experience, but
based on advice from the Elisp manual:

> [...] advice should be reserved for the cases where you cannot modify
> a function’s behavior in any other way. [...] In particular, 
> Emacs’s
> own source files should not put advice on functions in Emacs. (There
> are currently a few exceptions to this convention, but we aim to
> correct them.)

Here we do have a chance to modify the functions' behavior.

How about a sort of compromise between our approaches: provide
'json-read-object' and 'json-read-array' with pre- and post-read
callback functions, that are only called when they're set. That would
make it possible to leverage the power of 'json-read-object' and
'json-read-array' by binding the callback functions, without mixing
alien logic into them.

That would also make it a lot cleaner when adding other extensions to
them in the future, compared to my original suggestion.

If that sounds good to you, I'll cook up a new patch!

-- Simen