Print the json_value structure to an allocatable string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p | ||
character(kind=CK, len=:), | intent(out), | allocatable | :: | str |
prints structure to this string |
subroutine json_value_to_string(json,p,str) implicit none class(json_core),intent(inout) :: json type(json_value),pointer,intent(in) :: p character(kind=CK,len=:),intent(out),allocatable :: str !! prints structure to this string integer(IK) :: iloc !! used to keep track of size of str !! since it is being allocated in chunks. character(kind=CK,len=:),allocatable :: tmp !! temporary buffer for trimming `str` str = repeat(space, print_str_chunk_size) iloc = 0_IK call json%json_value_print(p, iunit=unit2str, str=str, iloc=iloc, indent=1_IK, colon=.true.) ! trim the string if necessary: if (len(str)>iloc) then allocate(character(kind=CK,len=iloc)::tmp) tmp(1:iloc) = str call move_alloc(tmp, str) endif end subroutine json_value_to_string