@@ -237,6 +237,13 @@ module json_value_module
237237 ! ! will also check for duplicates. If True
238238 ! ! [default] then no special checks are done
239239
240+ logical (LK) :: escape_solidus = .false. ! ! If True then the solidus "`/`" is always escaped
241+ ! ! ("`\/`") when serializing JSON.
242+ ! ! If False [default], then it is not escaped.
243+ ! ! Note that this option does not affect parsing
244+ ! ! (both escaped and unescaped versions are still
245+ ! ! valid in all cases).
246+
240247 contains
241248
242249 private
@@ -792,7 +799,8 @@ function initialize_json_core(verbose,compact_reals,&
792799 path_mode ,&
793800 path_separator ,&
794801 compress_vectors ,&
795- allow_duplicate_keys ) result(json_core_object)
802+ allow_duplicate_keys ,&
803+ escape_solidus ) result(json_core_object)
796804
797805 implicit none
798806
@@ -810,7 +818,8 @@ function initialize_json_core(verbose,compact_reals,&
810818 path_mode,&
811819 path_separator,&
812820 compress_vectors,&
813- allow_duplicate_keys)
821+ allow_duplicate_keys,&
822+ escape_solidus)
814823
815824 end function initialize_json_core
816825! *****************************************************************************************
@@ -845,7 +854,8 @@ subroutine json_initialize(me,verbose,compact_reals,&
845854 path_mode ,&
846855 path_separator ,&
847856 compress_vectors ,&
848- allow_duplicate_keys )
857+ allow_duplicate_keys ,&
858+ escape_solidus )
849859
850860 implicit none
851861
@@ -923,6 +933,11 @@ subroutine json_initialize(me,verbose,compact_reals,&
923933 me% allow_duplicate_keys = allow_duplicate_keys
924934 end if
925935
936+ ! if escaping the forward slash:
937+ if (present (escape_solidus)) then
938+ me% escape_solidus = escape_solidus
939+ end if
940+
926941 ! Set the format for real numbers:
927942 ! [if not changing it, then it remains the same]
928943
@@ -1975,7 +1990,7 @@ recursive subroutine json_value_destroy(json,p,destroy_next)
19751990 if (associated (child)) then
19761991 p% children = > p% children% next
19771992 p% n_children = p% n_children - 1
1978- call json_value_destroy( json, child,.false. )
1993+ call json% destroy( child,.false. )
19791994 else
19801995 call json% throw_exception(' Error in json_value_destroy: ' // &
19811996 ' Malformed JSON linked list' )
@@ -1986,7 +2001,7 @@ recursive subroutine json_value_destroy(json,p,destroy_next)
19862001 nullify(child)
19872002 end if
19882003
1989- if (associated (p% next) .and. des_next) call json_value_destroy( json, p% next)
2004+ if (associated (p% next) .and. des_next) call json% destroy( p% next)
19902005
19912006 if (associated (p% previous)) nullify(p% previous)
19922007 if (associated (p% parent)) nullify(p% parent)
@@ -2418,7 +2433,6 @@ subroutine json_value_validate(json,p,is_valid,error_msg)
24182433 logical (LK) :: has_duplicate ! ! to check for duplicate keys
24192434 character (kind= CK,len= :),allocatable :: path ! ! path to duplicate key
24202435 logical (LK) :: status_ok ! ! to check for existing exception
2421- logical (LK) :: status_ok2 ! ! to check for a new exception
24222436 character (kind= CK,len= :),allocatable :: exception_msg ! ! error message for an existing exception
24232437 character (kind= CK,len= :),allocatable :: exception_msg2 ! ! error message for a new exception
24242438
@@ -5257,7 +5271,7 @@ recursive subroutine json_value_print(json,p,iunit,str,indent,&
52575271
52585272 ! print the name
52595273 if (allocated (element% name)) then
5260- call escape_string(element% name,str_escaped)
5274+ call escape_string(element% name,str_escaped,json % escape_solidus )
52615275 if (json% no_whitespace) then
52625276 ! compact printing - no extra space
52635277 call write_it(repeat (space, spaces)// quotation_mark// &
@@ -5384,7 +5398,7 @@ recursive subroutine json_value_print(json,p,iunit,str,indent,&
53845398
53855399 if (allocated (p% str_value)) then
53865400 ! have to escape the string for printing:
5387- call escape_string(p% str_value,str_escaped)
5401+ call escape_string(p% str_value,str_escaped,json % escape_solidus )
53885402 call write_it( s// quotation_mark// &
53895403 str_escaped// quotation_mark, &
53905404 comma= print_comma, &
@@ -6863,7 +6877,7 @@ subroutine add_to_path(str,path_sep)
68636877 ! ! prepend the string to the path
68646878 implicit none
68656879 character (kind= CK,len=* ),intent (in ) :: str ! ! string to prepend to `path`
6866- character (kind= CK,len= 1 ),intent (in ),optional :: path_sep
6880+ character (kind= CK,len=* ),intent (in ),optional :: path_sep
68676881 ! ! path separator (default is '.').
68686882 ! ! (ignored if `json%path_mode/=1`)
68696883
@@ -7678,7 +7692,7 @@ subroutine json_get_string(json, me, value)
76787692 value = me% str_value
76797693 else
76807694 ! return the escaped version:
7681- call escape_string(me% str_value, value)
7695+ call escape_string(me% str_value, value, json % escape_solidus )
76827696 end if
76837697 else
76847698 call json% throw_exception(' Error in json_get_string: ' // &
0 commit comments