Parse and restructure key:value pair of JSON Object to Python Object

0 votes

Hi ,

I am trying to parse below JSON object output from a web server. This JSON object has just one entry but actual object has many entries. The problem is the way array is structured especially the desired key:value pair that I am looking at, are not in an appropriate format, as explained below:

Explanation:

Code Snippet from below JSON object:

{
"@columnnumber": "0",
"@name": "RequestNum",
"text": {
"0": "AG00106"
}
},

Where,

"@name": "RequestNum"  the column name i.e. key is "RequestNum"

"0": "AG00106" the column value i.e. value is "AG00106"

Is there a way I could transpose or change the out put so I could see something as following:

Desired Result in Python Object: { "RequestNum":"AG00106", "$1":"Alan Gosnell",.....}

Total number of columns are 28. Indexing starts with "0" 

JSON Object Code Snippet 

{
"@timestamp": "20200930T170223,92Z",
"@toplevelentries": "162",
"viewentry": [
{
"@position": "1",
"@unid": "B9AA53A48E4EFB208525858500684EA4",
"@noteid": "47C6",
"@siblings": "162",
"entrydata": [
{
"@columnnumber": "0",
"@name": "RequestNum",
"text": {
"0": "AG00106"
}
},
{
"@columnnumber": "1",
"@name": "$1",
"text": {
"0": "Alan Gosnell"
}
},
{
"@columnnumber": "2",
"@name": "Submitted",
"datetime": {
"0": "20200101T000000,00-05"
}
},
{
"@columnnumber": "3",
"@name": "Status",
"text": {
"0": "Open"
}
},
{
"@columnnumber": "4",
"@name": "$3",
"datetime": {
"0": "20200101T000000,00-05"
}
},
{
"@columnnumber": "5",
"@name": "$5",
"text": {
"0": "Alan Gosnell"
}
},
{
"@columnnumber": "6",
"@name": "BusArea",
"text": {
"0": "Logistics"
}
},
{
"@columnnumber": "7",
"@name": "$2",
"text": {
"0": "Brian Ramstetter"
}
},
{
"@columnnumber": "8",
"@name": "AreaOfImprovement",
"text": {
"0": "Productivity"
}
},
{
"@columnnumber": "9",
"@name": "Subject",
"text": {
"0": "SXe PORM OERM - multiple - needs a wholistic evaluation"
}
},
{
"@columnnumber": "10",
"@name": "Detail",
"text": {
"0": ""
}
},
{
"@columnnumber": "11",
"@name": "Savings",
"text": {
"0": ""
}
},
{
"@columnnumber": "12",
"@name": "BusPriority",
"text": {
"0": "Medium"
}
},
{
"@columnnumber": "13",
"@name": "ROIType",
"text": {
"0": ""
}
},
{
"@columnnumber": "14",
"@name": "Action",
"text": {
"0": "System Application"
}
},
{
"@columnnumber": "15",
"@name": "ApplicationImpacted",
"text": {
"0": "Warehouse Link"
}
},
{
"@columnnumber": "16",
"@name": "Comments",
"text": {
"0": ""
}
},
{
"@columnnumber": "17",
"@name": "ApplicationAssignComments",
"text": {
"0": ""
}
},
{
"@columnnumber": "18",
"@name": "AppCompleteAction",
"text": {
"0": ""
}
},
{
"@columnnumber": "19",
"@name": "AppCompleteComments",
"text": {
"0": "7"
}
},
{
"@columnnumber": "20",
"@name": "TrainingAssignComments",
"text": {
"0": ""
}
},
{
"@columnnumber": "21",
"@name": "TrainingCompleteComments",
"text": {
"0": ""
}
},
{
"@columnnumber": "22",
"@name": "TSCCompleteComments",
"text": {
"0": ""
}
},
{
"@columnnumber": "23",
"@name": "ReturnReason",
"text": {
"0": ""
}
},
{
"@columnnumber": "24",
"@name": "ReviewDate",
"text": {
"0": ""
}
},
{
"@columnnumber": "25",
"@name": "InProcessDate",
"text": {
"0": ""
}
},
{
"@columnnumber": "26",
"@name": "CompletedDate",
"text": {
"0": ""
}
},
{
"@columnnumber": "27",
"@name": "ClosedDate",
"text": {
"0": ""
}
}
]
}
Sep 30 in Python by Khushboo
• 120 points

edited Oct 1 by Gitika 85 views

Hey, @Khushboom,

Are you facing any error while executing your code?

1 answer to this question.

0 votes

@Khushboo,

Can you link to a correctly formatted JSON file? I was going to check it in a viewer and read it with pandas but the snippet is incomplete.

answered Oct 1 by Gitika
• 41,080 points

Related Questions In Python

0 votes
1 answer

How to find the value of a row in a csv file in python and print column and row of that value ?

Hello @Khanhh , Use panda to find the value of ...READ MORE

answered 4 days ago in Python by Niroj
• 65,500 points
49 views
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
1,959 views
0 votes
1 answer

Convert string list of dict from csv into JSON object in python

You can use the ast module Ex: import ast s = """[{'10': ...READ MORE

answered Sep 12, 2018 in Python by Priyaj
• 57,680 points
1,299 views
0 votes
1 answer

Convert string list of dict from csv into JSON object in python

You can use the ast module Ex: import ast s = """[{'10': ...READ MORE

answered Sep 24, 2018 in Python by Priyaj
• 57,680 points
146 views
–1 vote
1 answer

Python program that calculates and prints value according to formula

Try this: import math c = 50 h = 30 value ...READ MORE

answered Jan 8, 2019 in Python by Omkar
• 69,030 points
830 views
0 votes
1 answer

Is there a way to list out in-built variables and functions of Python?

The in-built variables and functions are defined ...READ MORE

answered May 14, 2019 in Python by Junaid
168 views
0 votes
1 answer

How to find the value of a row in a csv file in python?

If you want to find the value ...READ MORE

answered May 20, 2019 in Python by Sanam
429 views
0 votes
0 answers
0 votes
1 answer

How to check the memory usage of an object in python

Hi, @Roshni, You can use this code below: import ...READ MORE

answered Jun 26 in Python by Gitika
• 41,080 points
314 views
0 votes
1 answer

I want to generate Fibonacci sequence of 100 numbers in Linked list and then reverse in python

Hey,  You can go through the given example ...READ MORE

answered Oct 12 in Python by Gitika
• 41,080 points
16 views