skip to Main Content
["{"RequestedByUser":false,"RequestedBySystem":null,"RequestedBySellerNotification":null,"RequestedByPaymentNotification":true,"Reason":null,"CancellationDate":"2024-01-16T00:40:59.0928615+00:00"}"]

tryingjson_extract, jsonpath and nothing

2

Answers


  1. We have a JSON string inside a list. If you want to extract values from this JSON string, you can use the json module in Python.

    Try like this

    import json
    
    # Your input data
    data = ["{"RequestedByUser":false,"RequestedBySystem":null,"RequestedBySellerNotification":null,"RequestedByPaymentNotification":true,"Reason":null,"CancellationDate":"2024-01-16T00:40:59.0928615+00:00"}"]
    
    # Assuming there is only one element in the list, you can access it using data[0]
    json_data = json.loads(data[0])
    cancellation_date = json_data["CancellationDate"]
    print("CancellationDate:", cancellation_date)
    

    Output:

    CancellationDate: 2024-01-16T00:40:59.0928615+00:00
    
    Login or Signup to reply.
  2. I assume that you get a list of Json strings, from that you want to get the CancellationDate. You can do this in python, by loading the json string in the json module. Like this example:

    import json
    
    json_string_list = ["{"RequestedByUser":false,"RequestedBySystem":null,"RequestedBySellerNotification":null,"RequestedByPaymentNotification":true,"Reason":null,"CancellationDate":"2024-01-16T00:40:59.0928615+00:00"}"]
    new_json_list = []
    
    for json_string in json_string_list:
        try:
            json_dict = json.loads(json_string)
        except JSONDecodeError:
            continue
        new_json_list.append(json_dict)
    
    if new_json_list:
        print(new_json_list[0]["CancellationDate"])
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search