[PATCH 2/2] Generate correct json

Dirk Hohndel dirk at hohndel.org
Tue Aug 26 14:20:45 PDT 2014


On Tue, Aug 26, 2014 at 11:08:56PM +0200, Salvo Tomaselli wrote:
> Hello,
> 
> First, let me point out that the json parser of Python, rejecting because of 
> the extra commas is not wrong. That's how the format is defined.

I agree with you - we want to create correct JSON.

> I had started to fix the generation in a trivial way by changing all the bits 
> where it puts commas (I wasn't using a do..while so it didn't look as good as 
> the one Linus posted) but I got stuck in parts where there are functions 
> appending strings like "{stuff}," which would also need to be fixed.
> 
> It can certainly be fixed but it requires more work.
> 
> The "fixing" is done in two stages but could be changed to do the moving and 
> the scanning together, but I believe the code would be more complicated by 
> mixing scanning and moving together.
> Overall, the first step is O(n) and uses constant memory, while the 2nd step 
> depends on the amount of extra commas and their relative distance, but there 
> should be a somewhat linear correlation between that and the size of the 
> buffer.
> 
> Feel free to reject this if you think that it has to be done with a more 
> proper solution.

I appreciate the patch. But it feels to me that creating the incorrect
JSON and then doing a two level pass to fix it up later is... not the way
I want things done.

So I think the better solution is to talk Gehad into doing it right when
things are created.

/D


More information about the subsurface mailing list