JSON too slow in loop (or loops too slow in general)

Would you pls clarify what you mean?

Ok. Just wondering since my code needs no such accommodations. Thanks.

GetAsDate ( Substitute ( "2020-06-18" ; "-" ; "+" ) ) will convert the data to the system format for the date on the user's machine. This is incredibly light-weight code. In my testing, I've not seen it have more than a few millisecond different.

1 Like

Ok. I just wasn’t sure what you meant in your earlier reply. Thx.

IMHO, however, these “lightweight” hoops you jump through shouldn’t be necessary for the standard ISO date format FMP still does not support.

Also note that the data feed did not have the dashes in it like with your example below so that’s another step you need to code for?

MariaDB could still take “20200617” and convert to ISO date with no steps — all in DB.

I use a date API to convert date formats (when needed) — never string functions but that’s another difference.

just remember, this has no table for the data at start

so first run the script with "get initial data" to see the whole getdata/create/import

to watch the data now create a layout for the new table

than a second time with "get daily data" to get just a set of one day

really simple stuff

CoronaDataFMSoup.fmp12.zip (67.7 KB)

In the end, it's handled, so it's very inconsequential. If it serves the goal, then I use it. If it doesn't not, I go with a different approach. I will often use a data API to convert dates when needed also...but I don't always need to. The text functions in this case are just creating a format that FileMaker does recognize. Nothing more.

I think we all get you don't like the way FileMaker does many things... but it doesn't make them wrong. We use the tools for how they were meant to be used ( and maybe a little more ). :upside_down_face:

2 Likes

LOL. Thanks J.

I looked at this example, but didn't see where you populated, as my code did, the table for all 39 fields for all 5K+ rows. Those data tasks can take LOTS of time and was where my FMP attempts fell short (I was using the basic idea from the FMP JSON Help itself).

Did I miss that code somewhere?

Thanks for sharing what you did. :slight_smile:

Don't forget there is lots about FMP I like a lot and write about all the time, too. :slight_smile:

1 Like

Yup. Not mad at all. Just pointing some other perspectives that can be valuable to other readers, as well.

first: did you install a recent version of the MBS-Plugin?

second: there is no populating the way FM does, it is done with a function call to the MBS-Plugin, the function in the first run analyses the JSON structure, creates the table in the FM file and populates it with the data from memory

you have to rely on what is delivered - with all its ups and downs

I didn’t think you were “mad”. You always post so much useful info, it’s amazing.

2 Likes

I have MBS 10.2.

I was just trying to do an apples-to apples comparison to gauge performance. Since I have a fast working solution, I’m not going to invest additional time.

Thanks very much that posting.

And I think that is worth calling out. Again -- so that people who stop by and see this can benefit.

I try to make a point of staying familiar with what is in the Claris reference pages -- I love that part of the site, but I will agree that not all of the example code in the reference docs is as clear as I would prefer.

The code I used was the FMP19 online help — the portion about “working with JSON”. I modeled my approach directly from that example. Could not find another example online (only found three or four sites with FMP JSON examples) but could have missed it.

I don’t think FMI tested that help example code with a real world JSON file with 5K rows and 39 fields.

Thanks Steve. :+1:

That may be true. The examples are not necessarily optimized, and this is not specific to Claris. I remember years ago when VBA was fully implemented in AutoCAD with AutoCAD version 2000. In the help for VBA, many examples provided with some functions would not get 'compiled' in VBA . . . very frustrating :rage:.

I can't tell why, but it seems that many software editors don't consider seriously the documentation they provide. I don't tell this is the case with Claris. It's also something with example apps.

Whatever tool one uses, there is a need to work a lot to learn, and that means writing code that do not perform right. That'S the way it is.

Hi @anon45965781,

Now that you mention that example, I feel like I have a recollection of this happening before. If I have some time later today I may try to swing by the old site and post a request to update it. That would probably be a good thing to do. If you happen to have the link handy, and can post it here, that would be a big help.

Thank you!

Right.

But someone needs to test code in the help file and programming manuals. In this case it could point to a software performance issue.

Another example: Take a look at FMI’s JDBC reference. The one simple java program there has the disclaimer “not meant to be compiled”. Huh???Nobody at FMI could even come up with a simple example that could run with a sample FMP database? That omission never affected me but I don’t know about others.

Thanks.

Hey Steve,

From, here: https://help.claris.com/en/pro-help/#page/FMP_Help%2Fjson-functions.html

This is the code idea I used after changing for JSON structure:

Set Variable [ $ProductCount ; Value:
ValueCount (
JSONListKeys ( $$JSON ; "bakery.product" )
) ]
Set Variable [ $i ; Value: 0 ]
If [ $ProductCount > 0 ]
**Loop**
**Set Variable [ $ID ; Value:**
**JSON****GetElement ( $$****JSON** **; "bakery.product[" & $i & "]id" ) ]**
**If [ $ID = "FB3" ]**
**Set Variable [ $$****JSON** **; Value:**
**JSON****DeleteElement ( $$****JSON** **; "bakery.product[" & $i & "]" ) ]**
**Exit Script [ Text Result: 0 ]**
**End If**
**Set Variable [ $i ; Value: $i + 1 ]**
**Exit Loop If [ $i** **≄** **$ProductCount ]**
**End Loop**
End If

(lots of other possibly outdated samples there too)

Hope this helps! :slight_smile:

1 Like

Thanks for the link, @anon45965781. I submitted some constructive feedback regarding that page.

1 Like