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


Groups > comp.lang.python > #92979

Re: JSON Object to CSV File Troubleshooting

Path csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <liik.joonas@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'one?': 0.05; 'xml,': 0.05; 'json': 0.07; 'list?': 0.07; 'formatted': 0.09; 'throw': 0.09; 'cc:addr:python-list': 0.10; 'output': 0.15; "'0',": 0.16; 'alot': 0.16; 'csv': 0.16; 'data2': 0.16; 'emit': 0.16; 'json,': 0.16; 'naive': 0.16; 'result:': 0.16; 'sequential': 0.16; 'somehow.': 0.16; 'subject:CSV': 0.16; 'subject:File': 0.16; 'subject:Object': 0.16; '{"a":': 0.16; 'wrote:': 0.16; 'later': 0.16; 'config': 0.18; 'intermediate': 0.18; 'compare': 0.20; 'fix': 0.21; 'cc:2**0': 0.21; 'cc:addr:python.org': 0.21; '(the': 0.22; 'meant': 0.22; 'claiming': 0.22; 'explicit': 0.22; 'nested': 0.22; 'parsing': 0.22; 'produces': 0.22; 'pass': 0.22; 'decide': 0.23; '2015': 0.23; '(you': 0.23; 'insert': 0.23; 'originally': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; '(this': 0.24; 'properties': 0.24; 'second': 0.24; 'wondering': 0.25; 'xml': 0.27; 'entries': 0.27; 'yield': 0.27; 'message- id:@mail.gmail.com': 0.28; 'behaviour': 0.29; 'dictionary': 0.29; 'far,': 0.29; 'really,': 0.29; 'objects': 0.29; "skip:' 10": 0.30; 'winning': 0.31; 'entry': 0.31; 'code': 0.31; 'similar': 0.32; 'closely': 0.33; 'doubt': 0.33; 'wrap': 0.33; 'previous': 0.34; 'file': 0.34; 'add': 0.34; 'received:google.com': 0.34; 'lists': 0.34; 'could': 0.35; 'fail': 0.35; 'instance': 0.35; 'nothing.': 0.35; 'really': 0.35; 'list': 0.35; 'step': 0.36; 'but': 0.36; 'text': 0.36; 'there': 0.36; 'skip:{ 10': 0.36; 'should': 0.37; 'agree': 0.37; 'subject:: ': 0.37; 'missing': 0.37; 'rather': 0.38; 'feedback': 0.38; 'say': 0.38; 'doing': 0.38; 'end': 0.39; 'means': 0.39; 'things': 0.39; 'data': 0.40; 'some': 0.40; 'skip:u 10': 0.62; 'more': 0.62; 'subject:skip:T 10': 0.66; 'denis': 0.84; 'not)': 0.84; 'theres': 0.84; 'approach.': 0.91; 'steps.': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=Bb2tOU9OZ5qbXSwKJi3c0up3du2C+NwaJngbxO6hC0w=; b=gdQ4jZ7mTysO1VSafZSG6SnBfQuMBTDAidKl9v8neQdthF1EZXb96lIxRblpJI8I5y WSunE7KMpltvh916apI9B+wLlMhQQWjnwDveKqlOzJdGhTDGwkgs9/k9VrylwclGZIBK KcZSECV8MRuUj9ji8LnKE+YfQaP/OWx90XH9HnCgE81zzZ8/SL5FKXAZ7XBeROh4MS8E 2qzjjnF9X/9Y4P/T+gKx+kYZMNgH2FKoRA9AEHUSxAOkqJnQlAtgDH5RVKRVzpyTrsF1 fM9DnrhbD6msF5tzG7nwLrC8CVG/EABikTwlHcvUBOPVnu/oLDzm1vt2+2YFWnMxD0fs bgQQ==
MIME-Version 1.0
X-Received by 10.50.134.196 with SMTP id pm4mr16598057igb.6.1434923711905; Sun, 21 Jun 2015 14:55:11 -0700 (PDT)
In-Reply-To <44a2d55f-9312-4b70-8b23-637466b21b11@googlegroups.com>
References <d5bc266f-2e87-406f-b3f8-9c784112874b@googlegroups.com> <mm5n0u$5m8$5@dont-email.me> <44a2d55f-9312-4b70-8b23-637466b21b11@googlegroups.com>
Date Mon, 22 Jun 2015 00:55:11 +0300
Subject Re: JSON Object to CSV File Troubleshooting
From Joonas Liik <liik.joonas@gmail.com>
To Sahlusar <ahlusar.ahluwalia@gmail.com>
Cc Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.685.1434923721.13271.python-list@python.org> (permalink)
Lines 115
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1434923721 news.xs4all.nl 2969 [2001:888:2000:d::a6]:36355
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:92979

Show key headers only | View raw


On 21 June 2015 at 17:38, Sahlusar <ahlusar.ahluwalia@gmail.com> wrote:
>
> [snip]
> I do agree with you Denis that this is an unconventional approach. I was wondering then that perhaps I should add additional functionality at the XML to JSON step? So far, with JSON objects without nested lists (as values) I have been successful with this (the following is rather lengthy):
> [snip]


> ##JSON sample:
>
> data2 = {
>     "OTF": "0",
>     "F": "False",
>     "F": {
>         "Int32": ["0",
>         "0",
>         "0",
>         "0"]
>     },
> [snip]
>                 "PBDS": {
>                     "DateTime": ["1/1/0001 12:00:00 AM",
>                     "1/1/0001 12:00:00 AM",
>                     "1/1/0001 12:00:00 AM",
>                     "1/1/0001 12:00:00 AM"]
>                 },
>                 "PBDS": {
>                     "Double": ["0",
>                     "0",
>                     "0"]
>                 },
>                 "SCS": {
>                     "String": ["1",
>                     "2"]
>                 }
>             }
>
> The result:

and compare those closely now....

>
> {'D_B': ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
>  'F_Int32': ['0',
>   '0',
>   '0',
>   '0'],
>  'OTF': '0',
>  'PBDS_Double': ['0', '0', '0', '0', '0', '0', '0', '0'],
>  'SCS_String': ['1', '2']}
>
Notice in the original text you have 2 entries under the name F and
later 2 entiries under the name PBDS. in the result you are missing
the first entry of each.
you say you have succeeded in generating json, unless you meant to
throw away huge swafts of data i would say... nope..



[snip]
>
> I know that this is alot of sequential steps. I am wondering if I could insert or conditionally pass these functions when originally parsing the XML, so that the JSON is formatted for more recursive reading of the JSON dictionary and then writing to CSV? I welcome constructive feedback for refactoring....

theres things you could do to fix up the generated json .. tho really,

stop generating json when you need to generate csv.
you are winning nothing. you are losing.. well pretty much .. a little
of everything .. by doing this

there are fundemental properties of xml and json you fail to grasp,
you are touting code claiming that it works when the output it
produces is horribly deformed :(

In xml for instance this is valid:

<a>
 <b>1</b>
</a>
.. and so is this:
<a>
 <b>1</b>
 <b>2</b>
</a>

a naive translatio n of the first might yield
{"a":
 {"b":1}
}
but this will not work with the second example, it would emit
{"a":
 {"b":1,"b":2}
}
which really means
{"a":
 {"b":2}
}

if you insist on emitting json as an intermediate step you need to
take care of these inconsistencies somehow.
you need to decide which behaviour you want and be explicit about it.
is it desireable that the last entry overrites the previous one? (you
have this now, i doubt this is what you want)
would you like some mergine behaviour? (some config file might work
well with this, or not)
would you like to have every entry be a list? (this is simple, but you
will end up with a lot of junk like {a:[{b:[1]}]}
do you wrap some things in list but not others?

and the conversion from json to CSV has similar issues ofc.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

JSON Object to CSV File Troubleshooting Sahlusar <ahlusar.ahluwalia@gmail.com> - 2015-06-18 18:47 -0700
  Re: JSON Object to CSV File Troubleshooting Steve Hayes <hayesstw@telkomsa.net> - 2015-06-19 07:23 +0200
  Re: JSON Object to CSV File Troubleshooting Denis McMahon <denismfmcmahon@gmail.com> - 2015-06-21 06:50 +0000
  Re: JSON Object to CSV File Troubleshooting Denis McMahon <denismfmcmahon@gmail.com> - 2015-06-21 06:53 +0000
    Re: JSON Object to CSV File Troubleshooting Sahlusar <sahluwalia@wynyardgroup.com> - 2015-06-21 06:58 -0700
    Re: JSON Object to CSV File Troubleshooting Sahlusar <ahlusar.ahluwalia@gmail.com> - 2015-06-21 07:38 -0700
      Re: JSON Object to CSV File Troubleshooting Denis McMahon <denismfmcmahon@gmail.com> - 2015-06-21 21:06 +0000
      Re: JSON Object to CSV File Troubleshooting Joonas Liik <liik.joonas@gmail.com> - 2015-06-22 00:55 +0300
        Re: JSON Object to CSV File Troubleshooting Denis McMahon <denismfmcmahon@gmail.com> - 2015-06-21 23:33 +0000
          Re: JSON Object to CSV File Troubleshooting Sahlusar <ahlusar.ahluwalia@gmail.com> - 2015-06-21 16:56 -0700
            Re: JSON Object to CSV File Troubleshooting Denis McMahon <denismfmcmahon@gmail.com> - 2015-06-23 06:34 +0000
              Re: JSON Object to CSV File Troubleshooting Sahlusar <ahlusar.ahluwalia@gmail.com> - 2015-06-23 04:32 -0700
          Re: JSON Object to CSV File Troubleshooting Chris Angelico <rosuav@gmail.com> - 2015-06-23 10:43 +1000
        Re: JSON Object to CSV File Troubleshooting Sahlusar <ahlusar.ahluwalia@gmail.com> - 2015-06-21 16:42 -0700

csiph-web