Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add_by_path_otherways supports? #578

Open
LaplaceSoda opened this issue Aug 19, 2024 · 4 comments
Open

Add_by_path_otherways supports? #578

LaplaceSoda opened this issue Aug 19, 2024 · 4 comments

Comments

@LaplaceSoda
Copy link

LaplaceSoda commented Aug 19, 2024

It seems that the subroutine add_by_path only support the default way to specify the path (path_mode=1), actually the following codes does not work

program main
    use json_module
    implicit none
    type(json_file) :: new_json
    new_json = add_test()
    call new_json%print()
contains
    function add_test() result(json)
        type(json_file) :: json

        call json%initialize(path_mode=2)
        call json%add('/aaa', 123)
        call json%print()
    end function add_test
end program main

I wonder if this module can deal with the add_by_path with path_mode=2(or3) normally. If not, will there be an update to support it ?

@LaplaceSoda LaplaceSoda changed the title Add_by_path_otherMethod? Add_by_path_otherways? Aug 19, 2024
@LaplaceSoda LaplaceSoda changed the title Add_by_path_otherways? Add_by_path_otherways supports? Aug 19, 2024
@jacobwilliams
Copy link
Owner

jacobwilliams commented Aug 20, 2024

According to my comments:

!  It only works for `path_mode=1` or `path_mode=3`.
!  An error will be thrown for `path_mode=2` (RFC 6901).

And this note about path_mode=2:

            if (json%path_mode==2_IK) then
                ! the problem here is there isn't really a way to disambiguate
                ! the array elements, so '/a/0' could be 'a(1)' or 'a.0'.

So I guess it's not really possible? If anyone has a solution for this I would be interested to hear it.

@jacobwilliams
Copy link
Owner

The assumption could be made that numbers are always treated as array elements.

@LaplaceSoda
Copy link
Author

In my opinion, the add functions are just the reverse process of the get functions. So theoretically, if get can correctly recognize the path, then add should also recognize the path correctly.

@LaplaceSoda
Copy link
Author

LaplaceSoda commented Sep 3, 2024

The assumption could be made that numbers are always treated as array elements.

Maybe adding an optional flag argument to the add function which is only of use when there is /[\d+] in path and then letting developer choose the meaning of /[int] themselves would deal with this problem ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants