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


Groups > comp.lang.python > #91331

Re: Decoding JSON file using python

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'indices': 0.07; 'json': 0.07; 'subject:file': 0.07; 'subject:using': 0.09; 'typeerror:': 0.09; 'python': 0.11; 'subject:python': 0.14; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'integers,': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'skip:{ 40': 0.16; 'structure.': 0.16; 'wrote:': 0.16; 'string': 0.17; 'string,': 0.18; 'skip:" 40': 0.20; 'import': 0.24; 'header:In- Reply-To:1': 0.24; '(most': 0.24; 'header:User-Agent:1': 0.26; 'str': 0.29; 'error.': 0.31; 'code': 0.31; 'received:84': 0.32; 'structure': 0.32; 'getting': 0.33; 'skip:j 20': 0.33; 'traceback': 0.33; 'this?': 0.34; 'file': 0.34; 'to:addr:python- list': 0.35; 'subject:: ': 0.37; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'data': 0.40; 'different': 0.64; '\\n\\n': 0.84; 'dict.': 0.84
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=cblcrxzM c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=QrohdLjRRo4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=20eAzwmGAAAA:8 a=g8KEX7M-AAAA:8 a=OX15RKMA6Zx9Ty6CMmsA:9 a=QEXdDO2ut3YA:10
X-AUTH mrabarnett@:2500
Date Thu, 28 May 2015 00:08:42 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Decoding JSON file using python
References <11dbf982-efc1-4ef0-b286-e3d08ba5030e@googlegroups.com>
In-Reply-To <11dbf982-efc1-4ef0-b286-e3d08ba5030e@googlegroups.com>
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
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.105.1432768131.5151.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1432768131 news.xs4all.nl 2876 [2001:888:2000:d::a6]:56800
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:91331

Show key headers only | View raw


On 2015-05-27 23:23, Karthik Sharma wrote:
> I have the JSON structure shown below and the python code shown below to manipulate the JSON structure.
>
>      import json
>
>      json_input = {
>          "msgType": "0",
>          "tid": "1",
>          "data": "[{\"Severity\":\"warn\",\"Subject\":\"Reporting \",\"Message\":\"tdetails:{\\\"Product\\\":\\\"Gecko\\\",\\\"CPUs\\\":8,\\\"Language\\\":\\\"en-GB\\\",\\\"isEvent\\\":\\\">
>          "Timestamp": "1432703193431",
>          "Host": "myserver.com",
>          "Agent": "Experience",
>          "AppName": "undefined",
>          "AppInstance": "my_server",
>          "Group": "UndefinedGroup"
>      }
>
>
>      data = json_input['data']
>      tdetails = data['Message']
>      print('json_input {} \n\ndata {} \n\n tdetails {}\n\n'.format(json_input,data,tdetails))
>
> I am getting the error.
>
>      Traceback (most recent call last):
>        File "test_json.py", line 19, in <module>
>          tdetails = data['Message']
>      TypeError: string indices must be integers, not str
>
> The JSON structure is valid as shown by http://jsonlint.com/
>     I want to be able to access the different fields inside `data` such as `severity`, `subject` and also fields inside `tdetails` such as `CPUs` and `Product`. How do I do this?
>
json_input['Message'] is a string, not a dict.

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