0

I have this json file:

{
  "entityId": "12345",
  "displayName": "hostabc",
  "toRelationships": {
    "isProcessOf": [
      {
        "id": "proce123D00BB86",
        "type": "PROCESS_GROUP_INSTANCE"
      },
      {
        "id": "proc678DD0DBA4",
        "type": "PROCESS_GROUP_INSTANCE"
      },
      {
        "id": "proc978DD0DBA4",
        "type": "PROCESS_GROUP_INSTANCE"
      }
      
    ]
  }
}

I need to extract id fields under isProcessOf and build a data list.

I am new to python, how would I do this?

1

2 Answers 2

1

Looks like a list comprehension would do the job. You access dictionary values by its keys, so since you want to access 'id's of dictionaries in a list under the 'isProcessOf' key, which in turn is under the 'toRelationships' key, you can do it as:

out = [d['id'] for d in dct['toRelationships']['isProcessOf']]

Output:

['proce123D00BB86', 'proc678DD0DBA4', 'proc978DD0DBA4']
Sign up to request clarification or add additional context in comments.

Comments

0

I would use the json package in python and then read the data using list comprehension:

import json
file_dir = "<YOUR_FILE_DIR>"
with open(file_dir ) as f:
    data = json.load(f)
id_list = [process['id'] for process in data['toRelationships']['isProcessOf']]

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.