@@ -7275,14 +7275,16 @@ subroutine json_get_integer(json, me, value)
7275
7275
type (json_value),pointer ,intent (in ) :: me
7276
7276
integer (IK),intent (out ) :: value
7277
7277
7278
- value = 0
7278
+ logical (LK) :: status_ok ! ! for [[string_to_integer]]
7279
+
7280
+ value = 0_IK
7279
7281
if ( json% exception_thrown ) return
7280
7282
7281
7283
if (me% var_type == json_integer) then
7282
7284
value = me% int_value
7283
7285
else
7284
7286
if (json% strict_type_checking) then
7285
- call json% throw_exception(' Error in get_integer :' // &
7287
+ call json% throw_exception(' Error in json_get_integer :' // &
7286
7288
' Unable to resolve value to integer: ' // me% name)
7287
7289
else
7288
7290
! type conversions
@@ -7295,8 +7297,16 @@ subroutine json_get_integer(json, me, value)
7295
7297
else
7296
7298
value = 0
7297
7299
end if
7300
+ case (json_string)
7301
+ call string_to_integer(me% str_value,value,status_ok)
7302
+ if (.not. status_ok) then
7303
+ value = 0_IK
7304
+ call json% throw_exception(' Error in json_get_integer:' // &
7305
+ ' Unable to convert string value to integer: me.' // &
7306
+ me% name// ' = ' // trim (me% str_value))
7307
+ end if
7298
7308
case default
7299
- call json% throw_exception(' Error in get_integer :' // &
7309
+ call json% throw_exception(' Error in json_get_integer :' // &
7300
7310
' Unable to resolve value to integer: ' // me% name)
7301
7311
end select
7302
7312
end if
@@ -7491,6 +7501,8 @@ subroutine json_get_double(json, me, value)
7491
7501
type (json_value),pointer :: me
7492
7502
real (RK),intent (out ) :: value
7493
7503
7504
+ logical (LK) :: status_ok ! ! for [[string_to_real]]
7505
+
7494
7506
value = 0.0_RK
7495
7507
if ( json% exception_thrown ) return
7496
7508
@@ -7511,6 +7523,14 @@ subroutine json_get_double(json, me, value)
7511
7523
else
7512
7524
value = 0.0_RK
7513
7525
end if
7526
+ case (json_string)
7527
+ call string_to_real(me% str_value,value,status_ok)
7528
+ if (.not. status_ok) then
7529
+ value = 0.0_RK
7530
+ call json% throw_exception(' Error in json_get_double:' // &
7531
+ ' Unable to convert string value to double: me.' // &
7532
+ me% name// ' = ' // trim (me% str_value))
7533
+ end if
7514
7534
case default
7515
7535
call json% throw_exception(' Error in json_get_double:' // &
7516
7536
' Unable to resolve value to double: ' // me% name)
@@ -7703,6 +7723,13 @@ end subroutine wrap_json_get_double_vec_by_path
7703
7723
! *****************************************************************************************
7704
7724
! >
7705
7725
! Get a logical value from a [[json_value]].
7726
+ !
7727
+ ! ### Note
7728
+ ! If `strict_type_checking` is False, then the following assumptions are made:
7729
+ !
7730
+ ! * For integers: a value > 0 is True
7731
+ ! * For doubles: a value > 0 is True
7732
+ ! * For strings: 'true' is True, and everything else is false. [case sensitive match]
7706
7733
7707
7734
subroutine json_get_logical (json , me , value )
7708
7735
@@ -7726,7 +7753,11 @@ subroutine json_get_logical(json, me, value)
7726
7753
! type conversions
7727
7754
select case (me% var_type)
7728
7755
case (json_integer)
7729
- value = (me% int_value > 0 )
7756
+ value = (me% int_value > 0_IK )
7757
+ case (json_double)
7758
+ value = (me% int_value > 0.0_RK )
7759
+ case (json_string)
7760
+ value = (me% str_value == true_str)
7730
7761
case default
7731
7762
call json% throw_exception(' Error in json_get_logical: ' // &
7732
7763
' Unable to resolve value to logical: ' // &
0 commit comments