0

I have this json file.

{
  "entityId": "PROCESS_1234",
  "displayName": "Windows System",
  "firstSeenTms": 1619147697131,
  "lastSeenTms": 1653317760000,
  "properties": {
    "detectedName": "Windows System",
    "bitness": "32",
    "metadata": [],
    "awsNameTag": "Windows System",
    "softwareTechnologies": [
      {
        "type": "WINDOWS_SYSTEM"
      }
    ],
    "processType": "WINDOWS_SYSTEM"
    
    
  }
  
}

I need to extract entityId": "PROCESS_1234" and "properties": { "detectedName": "Windows System" as a data frame. The data frame needs to look like this:

entityId        detectedName
PROCESS_1234    Windows System

I have tried this:

print(resp2['entityId']['properties'][0]['detectedName'])

I get this error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-09b87f04b95e> in <module>
----> 1 print(resp2['entityId']['properties'][0]['detectedName'])

TypeError: string indices must be integers
3
  • there's a trailing ] on your json, below processType Commented May 23, 2022 at 17:05
  • 1
    If you select entityId, the value is now "PROCESS_1234" so when you select "property" it is not valid for strings Commented May 23, 2022 at 17:05
  • @Fed_Dragon I need to build a data frame this json Commented May 23, 2022 at 17:07

3 Answers 3

2

To extract entityId, do:

print(resp2['entityId'])

To extract detectedName, do:

print(resp2['properties']['detectedName'])
Sign up to request clarification or add additional context in comments.

2 Comments

print needs to print out entityId and detectedName in one line not different print statements
@user1471980 Do print(resp2['entityId'], resp2['properties']['detectedName'])
0

this error occur when you pass a string value

print(resp2[0][1]) try like this.

Comments

0

The program

import pandas as pd
data = {
  "entityId": "PROCESS_1234",
  "displayName": "Windows System",
  "firstSeenTms": 1619147697131,
  "lastSeenTms": 1653317760000,
  "properties": {
    "detectedName": "Windows System",
    "bitness": "32",
    "metadata": [],
    "awsNameTag": "Windows System",
    "softwareTechnologies": [
      {
        "type": "WINDOWS_SYSTEM"
      }
    ],
    "processType": "WINDOWS_SYSTEM"
  }
}

rows = [(data['entityId'], data['properties']['detectedName'])]
x = pd.DataFrame(data=rows, columns=['entityId', 'detectedName'])
print(x)

The output

bash-5.1$ python3 c.py
       entityId    detectedName
0  PROCESS_1234  Windows System

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.