@@ -851,7 +851,7 @@ end subroutine json_file_move_pointer
851851! end program main
852852! ```
853853
854- subroutine json_file_load (me , filename , unit )
854+ subroutine json_file_load (me , filename , unit , destroy_pointer )
855855
856856 implicit none
857857
@@ -860,8 +860,14 @@ subroutine json_file_load(me, filename, unit)
860860 integer (IK),intent (in ),optional :: unit ! ! the unit number to use
861861 ! ! (if not present, a newunit
862862 ! ! is used)
863+ logical (LK),intent (in ),optional :: destroy_pointer ! ! destroy the pointer before
864+ ! ! loading (default is True)
863865
864- call me% destroy()
866+ if (present (destroy_pointer)) then
867+ if (destroy_pointer) call me% destroy()
868+ else ! by default it is destroyed
869+ call me% destroy()
870+ end if
865871 call me% core% load(file= filename, p= me% p, unit= unit)
866872
867873 end subroutine json_file_load
@@ -881,14 +887,20 @@ end subroutine json_file_load
881887! call f%deserialize('{ "name": "Leonidas" }')
882888! ```
883889
884- subroutine json_file_load_from_string (me , str )
890+ subroutine json_file_load_from_string (me , str , destroy_pointer )
885891
886892 implicit none
887893
888894 class(json_file),intent (inout ) :: me
889895 character (kind= CK,len=* ),intent (in ) :: str ! ! string to load JSON data from
896+ logical (LK),intent (in ),optional :: destroy_pointer ! ! destroy the pointer before
897+ ! ! loading (default is True)
890898
891- call me% destroy()
899+ if (present (destroy_pointer)) then
900+ if (destroy_pointer) call me% destroy()
901+ else ! by default it is destroyed
902+ call me% destroy()
903+ end if
892904 call me% core% deserialize(me% p, str)
893905
894906 end subroutine json_file_load_from_string
0 commit comments