josephalevin / fson

Fortran 95 JSON Parser
60 stars 25 forks source link

Support default values in fson_get for non-existent paths #29

Open fangq opened 4 years ago

fangq commented 4 years ago

First, thank you for this wonderful library!

I just added fson to one of my f90 projects and decided to make fson_get calls to accept default values when a specified path does not exist. This is very convenient and allows one to use compact JSON inputs without needing all keys to present.

The default values are added as an optional argument to fson_get and should be fully backward compatible to existing codes. See updated sample code here:

https://github.com/fangq/fson/commit/6578fd2f5f3b014ebaf4dfed594792e8b75c2757#diff-084560e84ee2315a2388956bd315c7dcR63

If you are interested, feel free to take this patch and merge it to the upstream code. Suggestions on additional changes are welcome.