Skip to content

After creating an new object, any remaining key-value pairs in origin json_file will be erased. #564

Closed
@LaplaceSoda

Description

@LaplaceSoda

After creating an new object of json_file type from one json_file object, any remaining key-value pairs in origin json will be erased.

Environment

gfortran 13.2.0 (Built by MSYS2 project)
fpm 0.10.0, alpha

Reproduction

Here is the test.json

{
    "aaa": {
        "bbb": 1,
        "ccc": {
            "ddd": 2
        },
        "eee": 3,
        "fff": 4.5
    }
}

We try to get something from it in this main.f90 and separate a portion (which could be used as an input for another function)

program main
    use json_module
    implicit none

    type(json_file) :: temp_json
    type(json_value), pointer :: value
    type(json_file) :: new_json
    logical :: found

    call temp_json%initialize(path_mode=2)
    call temp_json%load('test.json')

    call temp_json%print()

    call temp_json%get("/aaa/ccc", value, found)
    new_json = json_file(value, path_mode=2)
    call new_json%print()
    ! call other_sub(new_json)

    call temp_json%print()
end program main

The result shows that something in origin json_file object has been removed after a new object is created. And we can no longer get any things from it.
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions