Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Json Parsing
#1
Hi Expert,

i wanted to extract below objects from json file, (valueObject,valueString)

"analyzeResult": {

    "documentResults": [

      {

        "docType": "custom:sampelform0205",

        "docTypeConfidence": 0.85,

        "fields": {

          "Report": {

            "type": "array",

            "valueArray": [

              {

                "type": "object",

                "valueObject": {

                  "machinary": {

                    "boundingBox": [

                      6.515,

                      1.62,

                      6.71,

                      1.62,

                      6.71,

                      1.675,

                      6.515,

                      1.675

                    ],

                    "elements": [

                      "#/readResults/0/lines/26/words/0"

                    ],

                    "page": 1,

                    "text": "34.70",

                    "type": "string",

                    "valueString": "34.70"

                  },
Could you help me with some sample code to extract
Larz60+ write May-04-2022, 02:16 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.
Reply
#2
You should post a working data and what you have tried.
When coming from json and serialized to Python,the data is a dictionary.
This dictionary will usually be a mix of dict and list.
To fix a part of it and parse something.
data = {
    "valueObject": {
        "machinary": {
            "boundingBox": [
                6.515,
                1.62,
                6.71,
                1.62,
                6.71,
                1.675,
                6.515,
                1.675,
            ],
        },
    }
}
>>> data["valueObject"]
{'machinary': {'boundingBox': [6.515,
                               1.62,
                               6.71,
                               1.62,
                               6.71,
                               1.675,
                               6.515,
                               1.675]}}
>>> 
>>> data["valueObject"]["machinary"]["boundingBox"]
[6.515, 1.62, 6.71, 1.62, 6.71, 1.675, 6.515, 1.675]
>>> data["valueObject"]["machinary"]["boundingBox"][0]
6.515 
Reply
#3
thanks will follow next time ... any sample code suggestion ... i am new to it
Reply
#4
(May-04-2022, 12:56 PM)sshree43 Wrote: any sample code suggestion ... i am new to it
Not specific,search json parsing python on web or here on forum you will find a lot.
A tips is to learn about dictionary(this is what you access/parse from) dict the data structure get back when use,
json module or Requests very common way to get data(json) from eg a API.
Then test stuff out,post code(with error/Traceback) if have trouble.
Reply
#5
suggestion please
Reply
#6
(May-04-2022, 04:37 PM)sshree43 Wrote: suggestion please
You have gotten suggestion,i have even fixed part of you data and show how you parse it.
You have posted none working data and no code of what you have tried😒
Parsing of full data is just the same way as shown just start with key name in dictionary higher up.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Parsing large JSON josvink66 5 724 Jan-10-2024, 05:46 PM
Last Post: snippsat
  Parsing JSON pyStund 4 3,084 Jul-31-2022, 02:02 PM
Last Post: pyStund
  json api data parsing elvis 0 951 Apr-21-2022, 11:59 PM
Last Post: elvis
  string indices must be integers when parsing Json ilknurg 3 6,470 Mar-10-2022, 11:02 AM
Last Post: DeaD_EyE
  Help Parsing JSON kfwydfo1x 5 4,673 Jan-26-2021, 10:42 AM
Last Post: DeaD_EyE
  Parsing JSON with backslashes bazcurtis 3 9,395 Feb-08-2020, 01:13 PM
Last Post: bazcurtis
  JSON parsing (nested) fakka 0 3,102 Nov-25-2019, 09:25 PM
Last Post: fakka
  Parsing json - dictionary with in dictionary krish216 6 3,715 Jul-30-2019, 10:01 PM
Last Post: cvsae
  JSON Parsing PythonLearner007 3 2,552 Jan-31-2019, 10:47 AM
Last Post: gontajones

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020