python - to read json file
<p>I'm new to JSON and Python, any help on this would be greatly appreciated. 
Below is my JSON file format:</p>

<pre><code>{
        "header": {
        "platform":"atm"
        "version":"2.0"
       }
        "details":[
       {
        "abc":"3"
        "def":"4"
       },
       {
        "abc":"5"
        "def":"6"
       },
       {
        "abc":"7"
        "def":"8"
       }    
      ]
    }
</code></pre>

<p>My requirement is to read the values of all <code>"abc"</code> <code>"def"</code> in details and add this is to a new list like this <code>[(1,2),(3,4),(5,6),(7,8)]</code>. The new list will be used to create a spark data frame.</p>

<p>I'm trying to understand your question as best as I can, but it looks like it was formatted poorly.</p>

<p>First off your json blob is not valid json, it is missing quite a few commas. This is probably what you are looking for:</p>

<pre><code>{
    "header": {
        "platform": "atm",
        "version": "2.0"
    },
    "details": [
        {
            "abc": "3",
            "def": "4"
        },
        {
            "abc": "5",
            "def": "6"
        },
        {
            "abc": "7",
            "def": "8"
        }
    ]
}
</code></pre>

<p>Now assuming you are trying to parse this in python you will have to do the following.</p>

<pre><code>import json

json_blob = '{"header": {"platform": "atm","version": "2.0"},"details": [{"abc": "3","def": "4"},{"abc": "5","def": "6"},{"abc": "7","def": "8"}]}'
json_obj = json.loads(json_blob)

final_list = []

for single in json_obj['details']:
    final_list.append((int(single['abc']), int(single['def'])))

print(final_list)
</code></pre>

<p>This will print the following: [(3, 4), (5, 6), (7, 8)]</p>

python json spark-dataframe