modelica-3rdparty / ExternData

:page_facing_up: Modelica library for data I/O of CSV, INI, JSON, MATLAB MAT, SSV, TIR, Excel XLS/XLSX and XML files
https://doi.org/10.3384/ecp21181141
BSD 2-Clause "Simplified" License
74 stars 30 forks source link

How to get value in array of structures in json? #49

Open Alex-Thunder-315 opened 5 months ago

Alex-Thunder-315 commented 5 months ago

If we have the next json: { "a" : 1.0, "b" : 2.0 } then we can get the value "a" using getReal("a").

How to get the value "a" for example of the first element "list" for the following example: { "list" : [ { "a" : 1, "b" : 2 }, { "a" : 2, "b" : 1 } ] } In the examples there is a case when an array of values is considered, but such a case is not considered, thanks.

beutlich commented 5 months ago

Obtaining individual data out of array is not yet supported by the library.

This sounds like a useful idea to add. "list[1].a" (with Modelica-like one-based indexing) might be some proper identifier for your task. (Note that there is no array-syntax support in the underlying parson lib itself).

Alex-Thunder-315 commented 5 months ago

Thanks for the answer. Yes, it would be great if processing of such json files was added.