Unable to save the updated file

Hi,
My scenario is to get json file from the path and overwrite id and save it in the existing path.
But after updating the id the file is not saved in the same path.
Here is my snippet

${post_json_data}=    Get File    ../json.txt
 
 ${parsed_json}=    Evaluate    json.dumps(${post_json_data})    json
 
 ${json_response}=    convert string to json    ${parsed_json}  
 ${id}=     Set Variable     ${json_response['id'][0]['chars']['id']}
 Log    ${json_response}  
 Log    ${id}
 Set To Dictionary    $json_responseid[0].chars["ID"]]    2222
 ${new_ID}=    Set Variable    $json_response['id'][0]   2222
 Log    ${${new_ID}}
     
 ${updated_json}=    Evaluate    json.dumps(${json_response}, indent=4)    json
 Set Global Variable    ${updated_json}
 #Create File    ../json.txt    ${parsed_json}
 Write To File1     ../json.txt      data=${parsed_json}

Thanks,
Surya

Hi,
My scenario is to get json file from the path and overwrite id and save it in the existing path.
But after updating the id the file is not saved in the same path. And the id is not updated.

Hi Surya,

From the documentation for Create File:

Possible existing file is overwritten.

So this line:

#Create File    ../json.txt    ${parsed_json}

Should have done what you wanted unless:

  • The file is locked for writes by another process
  • The user account running this test doesn’t have permissions to write to that file
  • ${parsed_json} is not a string? I’m actually not sure how Create File would handle a dictonary, so perhaps that line should have been:
Create File    ../json.txt    ${updated_json}

Also this line:

${parsed_json}=    Evaluate    json.dumps(${post_json_data})    json

should probably be:

${parsed_json}=    Evaluate    json.loads(${post_json_data})    json

But with all these things I’ve mentioned you should have had a failed test and the errors in the loh.html to tell you where the problem was

Hopefully the things I mentioned will help, if your still having issues, show the errors you get and mention which line gives them to you.

Dave.