Presenting recursive dict (json_diff)

2011-10-27 Thread mcepl
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):


  
 
'c' = 3
  
  
'b' = 2
--
  
  
'a' = 2
  
  
children
  
  
*
son = 'Ivánek'
  
  
*
daughter =
'Maruška'
  


but I cannot say I like it. Any suggestions?

Thank,

Matěj
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Presenting recursive dict (json_diff)

2011-10-27 Thread mcepl
On 27 říj, 10:50, 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

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"
}
}
}
}
-- 
http://mail.python.org/mailman/listinfo/python-list