| 1 | program test_json |
| 2 | use json_module |
| 3 | use iso_fortran_env, only: real64 |
| 4 | implicit none |
| 5 | |
| 6 | type(json_value_t) :: json_obj |
| 7 | character(len=100) :: json_str |
| 8 | real(real64) :: id_value |
| 9 | |
| 10 | ! Test with a simple JSON response like what we get from clangd |
| 11 | json_str = '{"id":1,"jsonrpc":"2.0","result":{"capabilities":{}}}' |
| 12 | |
| 13 | print *, "Testing JSON: ", trim(json_str) |
| 14 | |
| 15 | ! Parse it |
| 16 | json_obj = json_parse(json_str) |
| 17 | |
| 18 | ! Check if we can find the id |
| 19 | if (json_has_key(json_obj, "id")) then |
| 20 | print *, "Found id key!" |
| 21 | id_value = json_get_number(json_obj, "id", -1.0_real64) |
| 22 | print *, "ID value: ", id_value |
| 23 | else |
| 24 | print *, "No id key found" |
| 25 | end if |
| 26 | |
| 27 | ! Check for jsonrpc |
| 28 | if (json_has_key(json_obj, "jsonrpc")) then |
| 29 | print *, "Found jsonrpc key!" |
| 30 | else |
| 31 | print *, "No jsonrpc key found" |
| 32 | end if |
| 33 | |
| 34 | end program test_json |