Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_file), | intent(inout) | :: | me | |||
character(kind=CDK,len=*), | intent(in) | :: | filename | filename to print to |
Print the JSON structure to the specified filename. The file is opened, printed, and then closed.
Example loading a JSON file, changing a value, and then printing result to a new file:
type(json_file) :: f logical :: found call f%load_file('my_file.json') !open the original file call f%update('version',4,found) !change the value of a variable call f%print_file('my_file_2.json') !save file as new name
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer(kind=IK), | public | :: | iunit | ||||
integer(kind=IK), | public | :: | istat |
subroutine json_file_print_2(me,filename)
implicit none
class(json_file),intent(inout) :: me
character(kind=CDK,len=*),intent(in) :: filename !! filename to print to
integer(IK) :: iunit,istat
open(newunit=iunit,file=filename,status='REPLACE',iostat=istat FILE_ENCODING )
if (istat==0) then
call me%print_file(iunit) !call the other routine
close(iunit,iostat=istat)
else
call throw_exception('Error in json_file_print_2: could not open file: '//&
trim(filename))
end if
end subroutine json_file_print_2