Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #15029 > unrolled thread

Presenting recursive dict (json_diff)

Started bymcepl <mcepl@redhat.com>
First post2011-10-27 01:50 -0700
Last post2011-10-28 00:18 -0400
Articles 5 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Presenting recursive dict (json_diff) mcepl <mcepl@redhat.com> - 2011-10-27 01:50 -0700
    Re: Presenting recursive dict (json_diff) mcepl <mcepl@redhat.com> - 2011-10-27 02:24 -0700
    Re: Presenting recursive dict (json_diff) Terry Reedy <tjreedy@udel.edu> - 2011-10-27 15:49 -0400
      Re: Presenting recursive dict (json_diff) Matej Cepl <mcepl@redhat.com> - 2011-10-27 22:58 +0200
        Re: Presenting recursive dict (json_diff) Terry Reedy <tjreedy@udel.edu> - 2011-10-28 00:18 -0400

#15029 — Presenting recursive dict (json_diff)

Frommcepl <mcepl@redhat.com>
Date2011-10-27 01:50 -0700
SubjectPresenting recursive dict (json_diff)
Message-ID<cb9e6eb1-b5a7-4df6-a212-4d953d3f85e5@a17g2000yqj.googlegroups.com>
Hi,

I have here a simple script (https://gitorious.org/json_diff/mainline)
which makes a diff between two JSON files. So for JSON objects

{
    "a": 1,
    "b": 2,
    "son": {
        "name": "Janošek"
    }
}

and

{
    "a": 2,
    "c": 3,
    "daughter": {
        "name": "Maruška"
    }
}

it generates

{
    "append": {
        "c": 3,
        "daughter": {
            "name": "Maruška"
        }
    },
    "remove": {
        "b": 2,
        "son": {
            "name": "Janošek"
        }
    },
    "update": {
        "a": 2
    }
}

(obvious problems with name conflicts between internal keys and the
investigated keys will be somehow addressed later; any simple Pythonic
suggestions how?)

Now, I would like to create a script (or class) to present such diff
object in HTML (and mind you the diffs might be large, hopefully not
too much deeply nested, by with many many keys).

Any suggestions how to do it? Any libraries to use? I would love to
use some templating language, but I am not sure which simple ones
(e.g., I like pystache) could do recursive templating. So currently I
am tending towards generating strings.

I am currently tending towards something like (not cleaned to be CSS-
only yet):

    <table>
      <tr>
        <td>&#160;</td>
        <td class="append_class">'c' = 3</td>
      </tr>
      <tr>
        <td class="remove_class">'b' = 2</td>
        <td>--</td>
      </tr>
      <tr>
        <td class="update_class" colspan="2">'a' = 2</td>
      </tr>
      <tr>
        <td class="update_class" colspan="2">children</td>
      </tr>
      <tr>
        <td>*</td>
        <td class="update_class" colspan="2">son = 'Ivánek'</td>
      </tr>
      <tr>
        <td>*</td>
        <td class="append_class" colspan="2">daughter =
        'Maruška'</td>
      </tr>
    </table>

but I cannot say I like it. Any suggestions?

Thank,

Matěj

[toc] | [next] | [standalone]


#15031

Frommcepl <mcepl@redhat.com>
Date2011-10-27 02:24 -0700
Message-ID<f6fcaca3-c92d-4be4-8430-8098941a8ecc@j39g2000yqc.googlegroups.com>
In reply to#15029
On 27 říj, 10:50, mcepl <mc...@redhat.com> wrote:
> Hi,
>
> I have here a simple script (https://gitorious.org/json_diff/mainline)
> which makes a diff between two JSON files. So for JSON objects

and I have completely burried to lead on this. The point is that the
resulting object can be endlessly recursively nested. On each level I
can have not only append/remove/update subobjects, but also number of
subtrees. Something like this would be better picture:

{
    "append": {
        "c": 3
    },
    "remove": {
        "b": 2
    },
    "update": {
        "a": 2,
        "children": {
            "update": {
                "son": "Ivánek"
            },
            "append": {
                "daughter": "Maruška"
            }
        }
    }
}

[toc] | [prev] | [next] | [standalone]


#15055

FromTerry Reedy <tjreedy@udel.edu>
Date2011-10-27 15:49 -0400
Message-ID<mailman.2265.1319745006.27778.python-list@python.org>
In reply to#15029
On 10/27/2011 4:50 AM, mcepl wrote:
> Hi,
>
> I have here a simple script (https://gitorious.org/json_diff/mainline)
> which makes a diff between two JSON files. So for JSON objects
>
> {
>      "a": 1,
>      "b": 2,
>      "son": {
>          "name": "Janošek"
>      }
> }
>
> and
>
> {
>      "a": 2,
>      "c": 3,
>      "daughter": {
>          "name": "Maruška"
>      }
> }
>
> it generates
>
> {
>      "append": {
>          "c": 3,
>          "daughter": {
>              "name": "Maruška"
>          }
>      },
>      "remove": {
>          "b": 2,
>          "son": {
>              "name": "Janošek"
>          }
>      },
>      "update": {
>          "a": 2
>      }
> }
>
> (obvious problems with name conflicts between internal keys and the
> investigated keys will be somehow addressed later; any simple Pythonic
> suggestions how?)

Use '_append', etc, much like namedtuple does, for the same reason.

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#15060

FromMatej Cepl <mcepl@redhat.com>
Date2011-10-27 22:58 +0200
Message-ID<j8cgk1$1kok$1@ns.felk.cvut.cz>
In reply to#15055
Dne 27.10.2011 21:49, Terry Reedy napsal(a):
> Use '_append', etc, much like namedtuple does, for the same reason.

Right, done. What about the presentation issue? Any ideas?

Best,

Matěj

[toc] | [prev] | [next] | [standalone]


#15087

FromTerry Reedy <tjreedy@udel.edu>
Date2011-10-28 00:18 -0400
Message-ID<mailman.2276.1319775615.27778.python-list@python.org>
In reply to#15060
On 10/27/2011 4:58 PM, Matej Cepl wrote:
> Dne 27.10.2011 21:49, Terry Reedy napsal(a):
>> Use '_append', etc, much like namedtuple does, for the same reason.
>
> Right, done. What about the presentation issue? Any ideas?

No.

-- 
Terry Jan Reedy

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web