-
Notifications
You must be signed in to change notification settings - Fork 86
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
Arrays in arrays #202
Comments
Hi Rudy, It looks like you’ll have to create a new object to contain program test
use json_module
use iso_fortran_env, only: output_unit
implicit none
integer :: i
integer,parameter :: WayPointsNumber = 3
integer,dimension(WayPointsNumber),parameter :: latWayPoints = 1
integer,dimension(WayPointsNumber),parameter :: lonWayPoints = 2
integer,dimension(WayPointsNumber),parameter :: DelayInHoursWayPoints = 3
type(json_value),pointer :: e,f,g,h,json_AnalysisIssues,root,p
type(json_core) :: jsonc
call jsonc%create_object(root,'') !create root object
! 3.3 WayPoints
call jsonc%create_array(f,'ValidatorRequests')
call jsonc%create_array(e,'WayPoints')
do i=1,WayPointsNumber
call jsonc%create_object(h,'')
call jsonc%add(h,'Lat',latWayPoints(i))
call jsonc%add(h,'Lon',lonWayPoints(i))
call jsonc%add(h,'DelayInHours',DelayInHoursWayPoints(i))
call jsonc%add(e,h)
nullify(h) !cleanup
enddo
call jsonc%create_object(p,'') !create object to contain e array
call jsonc%add(p,e) !add e array to p
call jsonc%add(f,p) !add p to f array
call jsonc%add(root,f) !add f array to the root structure
call jsonc%print(root,output_unit)
end program test So, I created an object {
"ValidatorRequests": [
{
"WayPoints": [
{
"Lat": 1,
"Lon": 2,
"DelayInHours": 3
},
{
"Lat": 1,
"Lon": 2,
"DelayInHours": 3
},
{
"Lat": 1,
"Lon": 2,
"DelayInHours": 3
}
]
}
]
} Presumably, if the Also you need to first create the Also note that your first: call jsonc%add(root,f) !add f to the root structure
nullify(f) !no longer need this is not correct, since you haven’t created |
Thanks Jacob ! Clear. |
Is this true? My reading of json.org is that it is legal JSON to have arrays of arrays since:
|
I think you're right, and I was mistaken. I guess I did know this at one point (see #156) but forgot. |
A question from an email:
Hi Jacob,
First of all thanks for your json fortran api.
I am facing an issue when trying to create an array “Waypoints” within an array “ValidatorRequests” to get the following structure:
Objective:
However when I create an array within an array, the array name , here “Waypoints” in yellow above is missing below.
Do you have any idea what’s going on here ? I am really new to json … so I guess it is trivial but I can’t see it.
Result of my code:
And here my code
Thanks a lot in advance,
Rudy
The text was updated successfully, but these errors were encountered: