json-fortran icon indicating copy to clipboard operation
json-fortran copied to clipboard

API Questions and Critiques

Open everythingfunctional opened this issue 2 years ago • 1 comments

Based on this example usage (although perhaps there are more examples that make this clearer, if so please point me towards them), it is unclear to me how the arguments to the get calls correspond to what data this example expects to have been in the file. Perhaps you could add a comment there to specify what it should be?

Based on that example, it appears that get is a generic interface, and thus the specific procedure is determined based on the type of the argument. So how does one determine what the actual type of an element in the JSON is? And is it possible to access an array of elements of different types?

Suppose I'm trying to deserialize a compound object, is it possible to "get" an object to pass to the constructor of one of the components. I.e.

function compound_from_json(json) result(compound)
  type(json_file), intent(in) :: json
  type(compound_t) :: compound

  type(??) :: first_component, second_component, ...

  call json%get('first', first_component)
  call json%get('second', second_component)
  ...
  compound%first_component = first_component_t(first_component)
  compound%second_component = second_component_t(second_component)
  ...
end function

Do you have an example of constructing the JSON? Is it easy to compose for e.g. serializing a compound object like above?

everythingfunctional avatar Nov 01 '21 20:11 everythingfunctional

Yep, I can work up an example for you when I get a chance.

The documentation does need to be improved. See also #233. Note: you could also look at the src/tests but it's not really that user friendly to find what you need. What we need are some examples written as use cases for common things that users might want to do.

jacobwilliams avatar Nov 06 '21 14:11 jacobwilliams