@@ -237,6 +237,13 @@ module json_value_module
237
237
! ! will also check for duplicates. If True
238
238
! ! [default] then no special checks are done
239
239
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
+
240
247
contains
241
248
242
249
private
@@ -792,7 +799,8 @@ function initialize_json_core(verbose,compact_reals,&
792
799
path_mode ,&
793
800
path_separator ,&
794
801
compress_vectors ,&
795
- allow_duplicate_keys ) result(json_core_object)
802
+ allow_duplicate_keys ,&
803
+ escape_solidus ) result(json_core_object)
796
804
797
805
implicit none
798
806
@@ -810,7 +818,8 @@ function initialize_json_core(verbose,compact_reals,&
810
818
path_mode,&
811
819
path_separator,&
812
820
compress_vectors,&
813
- allow_duplicate_keys)
821
+ allow_duplicate_keys,&
822
+ escape_solidus)
814
823
815
824
end function initialize_json_core
816
825
! *****************************************************************************************
@@ -845,7 +854,8 @@ subroutine json_initialize(me,verbose,compact_reals,&
845
854
path_mode ,&
846
855
path_separator ,&
847
856
compress_vectors ,&
848
- allow_duplicate_keys )
857
+ allow_duplicate_keys ,&
858
+ escape_solidus )
849
859
850
860
implicit none
851
861
@@ -923,6 +933,11 @@ subroutine json_initialize(me,verbose,compact_reals,&
923
933
me% allow_duplicate_keys = allow_duplicate_keys
924
934
end if
925
935
936
+ ! if escaping the forward slash:
937
+ if (present (escape_solidus)) then
938
+ me% escape_solidus = escape_solidus
939
+ end if
940
+
926
941
! Set the format for real numbers:
927
942
! [if not changing it, then it remains the same]
928
943
@@ -1975,7 +1990,7 @@ recursive subroutine json_value_destroy(json,p,destroy_next)
1975
1990
if (associated (child)) then
1976
1991
p% children = > p% children% next
1977
1992
p% n_children = p% n_children - 1
1978
- call json_value_destroy( json, child,.false. )
1993
+ call json% destroy( child,.false. )
1979
1994
else
1980
1995
call json% throw_exception(' Error in json_value_destroy: ' // &
1981
1996
' Malformed JSON linked list' )
@@ -1986,7 +2001,7 @@ recursive subroutine json_value_destroy(json,p,destroy_next)
1986
2001
nullify(child)
1987
2002
end if
1988
2003
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)
1990
2005
1991
2006
if (associated (p% previous)) nullify(p% previous)
1992
2007
if (associated (p% parent)) nullify(p% parent)
@@ -2418,7 +2433,6 @@ subroutine json_value_validate(json,p,is_valid,error_msg)
2418
2433
logical (LK) :: has_duplicate ! ! to check for duplicate keys
2419
2434
character (kind= CK,len= :),allocatable :: path ! ! path to duplicate key
2420
2435
logical (LK) :: status_ok ! ! to check for existing exception
2421
- logical (LK) :: status_ok2 ! ! to check for a new exception
2422
2436
character (kind= CK,len= :),allocatable :: exception_msg ! ! error message for an existing exception
2423
2437
character (kind= CK,len= :),allocatable :: exception_msg2 ! ! error message for a new exception
2424
2438
@@ -5257,7 +5271,7 @@ recursive subroutine json_value_print(json,p,iunit,str,indent,&
5257
5271
5258
5272
! print the name
5259
5273
if (allocated (element% name)) then
5260
- call escape_string(element% name,str_escaped)
5274
+ call escape_string(element% name,str_escaped,json % escape_solidus )
5261
5275
if (json% no_whitespace) then
5262
5276
! compact printing - no extra space
5263
5277
call write_it(repeat (space, spaces)// quotation_mark// &
@@ -5384,7 +5398,7 @@ recursive subroutine json_value_print(json,p,iunit,str,indent,&
5384
5398
5385
5399
if (allocated (p% str_value)) then
5386
5400
! 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 )
5388
5402
call write_it( s// quotation_mark// &
5389
5403
str_escaped// quotation_mark, &
5390
5404
comma= print_comma, &
@@ -7678,7 +7692,7 @@ subroutine json_get_string(json, me, value)
7678
7692
value = me% str_value
7679
7693
else
7680
7694
! return the escaped version:
7681
- call escape_string(me% str_value, value)
7695
+ call escape_string(me% str_value, value, json % escape_solidus )
7682
7696
end if
7683
7697
else
7684
7698
call json% throw_exception(' Error in json_get_string: ' // &
0 commit comments