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


Groups > comp.lang.python > #91348

Re: Decoding JSON file using python

Path csiph.com!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <cameron@cskk.homeip.net>
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; 'modify': 0.04; 'string.': 0.04; 'skip:\\ 20': 0.05; 'debugging.': 0.07; 'json': 0.07; 'modifying': 0.07; 'skip:\\ 10': 0.07; 'subject:file': 0.07; 'exception,': 0.09; 'skip:\\ 30': 0.09; 'subject:using': 0.09; 'exception': 0.13; 'subject:python': 0.14; '>on': 0.16; '>they': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'hint:': 0.16; 'message- id:@cskk.homeip.net': 0.16; 'quoted': 0.16; 'reproducing': 0.16; 'said.': 0.16; 'simpson': 0.16; 'wrote:': 0.16; 'looked': 0.16; 'input': 0.18; 'changes': 0.20; 'first,': 0.20; 'fix': 0.21; 'meant': 0.22; 'parsing': 0.22; 'module': 0.23; 'errors': 0.23; "i've": 0.24; 'tried': 0.24; 'import': 0.24; 'header:In-Reply- To:1': 0.24; 'thus': 0.24; 'header:User-Agent:1': 0.26; 'skip:" 20': 0.26; 'raw': 0.27; 'follows': 0.29; 'correct': 0.29; 'work.': 0.30; 'print': 0.31; 'trouble': 0.31; 'code': 0.31; 'to:addr :python-list': 0.35; 'really': 0.35; 'but': 0.36; "didn't": 0.37; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'does': 0.39; 'to:addr:python.org': 0.39; 'seem': 0.39; 'data': 0.40; 'content- disposition:inline': 0.60; 'your': 0.60; 'per': 0.61; 'different': 0.64; 'cameron': 0.66; 'below.': 0.66; 'received:61': 0.72; '>you': 0.84; 'actually,': 0.84; 'etc,': 0.84; 'suggestion,': 0.84
X-Authentication-Info Submitted using ID cskk@bigpond.com
X-Authority-Analysis v=2.0 cv=D6DF24tj c=1 sm=1 a=wlK6PSMovxJVZ0xpcBuegA==:17 a=yEdEr6MRgwAA:10 a=kj9zAlcOel0A:10 a=vrnE16BAAAAA:8 a=ZtCCktOnAAAA:8 a=h1PgugrvaO0A:10 a=Lpnxw2taAAAA:8 a=pGLkceISAAAA:8 a=20eAzwmGAAAA:8 a=oqAdNJufS8G0U2SllsMA:9 a=CjuIK1q_8ugA:10 a=M2ogJ6dkwzhOXYXO:21 a=9o4E4LMzzvof3etq:21 a=wlK6PSMovxJVZ0xpcBuegA==:117
Date Thu, 28 May 2015 13:32:39 +1000
From Cameron Simpson <cs@zip.com.au>
To python-list@python.org
Subject Re: Decoding JSON file using python
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii; format=flowed
Content-Disposition inline
In-Reply-To <slrnmmcsfd.1t4.jon+usenet@frosty.unequivocal.co.uk>
User-Agent Mutt/1.5.23 (2014-03-12)
References <slrnmmcsfd.1t4.jon+usenet@frosty.unequivocal.co.uk>
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.117.1432785446.5151.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1432785446 news.xs4all.nl 2900 [2001:888:2000:d::a6]:54827
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:91348

Show key headers only | View raw


On 28May2015 01:38, Jon Ribbens <jon+usenet@unequivocal.co.uk> wrote:
>On 2015-05-27, Karthik Sharma <karthik.sharma@gmail.com> wrote:
>> I tried modifying the program as follows as per your
>> suggestion.Doesn't seem to work.
>
>That's because you didn't modify the program as per their suggestion,
>you made completely different changes that bore no relation to what
>they said.

Actually, his changes looked good to me. He does print from data first, but 
only for debugging. Then he goes:

  message = json.loads(data)

and tried to access message['Message'].

However I am having trouble reproducing his issue because his quoted code is 
incorrect. I've tried to fix it, as listed below, but I don't know what is 
really meant to be in the 'data" string.

Hint: Karthik, use raw strings (r'foo') for complicated strings - it avoids a 
lot of backslashing etc, and thus avoids errors in backslashing.

Karthik, please correct the code below. Currently I do not get your exception, 
I get an exception from the JSON module parsing the "data" string.

Code below,
Cameron Simpson <cs@zip.com.au>

import json

json_input = { "msgType": "0",
    "tid": "1",
    "data": r'[{"Severity":"warn","Subject":"Reporting ","Message":"tdetails": {"Product":"Gecko","CPUs":8,"Language":"en-GB","isEven t":">}]',
    "Timestamp": "1432703193431",
    "Host": "myserver.com",
    "Agent": "Experience",
    "AppName": "undefined",
    "AppInstance": "my_server",
    "Group": "UndefinedGroup"
}

print('json input original  {} \n\n'.format(json_input))

data = json_input['data']
print('data {} \n\n'.format(data))

message = json.loads(data)
print('message {} \n\n'.format(message['Message']))

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


Thread

Decoding JSON file using python Karthik Sharma <karthik.sharma@gmail.com> - 2015-05-27 15:23 -0700
  Re: Decoding JSON file using python random832@fastmail.us - 2015-05-27 19:06 -0400
  Re: Decoding JSON file using python MRAB <python@mrabarnett.plus.com> - 2015-05-28 00:08 +0100
  Re: Decoding JSON file using python Cameron Simpson <cs@zip.com.au> - 2015-05-28 08:52 +1000
    Re: Decoding JSON file using python Karthik Sharma <karthik.sharma@gmail.com> - 2015-05-27 16:51 -0700
      Re: Decoding JSON file using python Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-05-28 01:38 +0000
        Re: Decoding JSON file using python Cameron Simpson <cs@zip.com.au> - 2015-05-28 13:32 +1000
          Re: Decoding JSON file using python Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-28 18:49 +0000
      Re: Decoding JSON file using python random832@fastmail.us - 2015-05-27 23:48 -0400
      Re: Decoding JSON file using python MRAB <python@mrabarnett.plus.com> - 2015-05-28 04:54 +0100
  Re: Decoding JSON file using python Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-28 18:48 +0000

csiph-web