cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Instantly extract effect sizes, F-ratios, and FDR-adjusted p-values from your models with the Calculate Effects Sizes extension, available now in the JMP Marketplace!
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Use World Cup data to build models, explore spatial relationships, and create informative visualizations in JMP. Register. July 17, 2 pm US Eastern Time.

JMP Wish List

We want to hear your ideas for improving JMP. Share them here.
Choose Language Hide Translation Bar
0 Kudos

Parse JSON error handling

Parse JSON() is hard to use because it does not handle errors nicely. In a callback, perhaps from RunProgram or a button, it will create an unwanted model dialog announcing the failure. It will also announce the failure in the log. It takes extra JSL to fix it up:

New Window( "parsejson",
    Button Box( "parse",
        local( {birestore, errText},
            birestore = Batch Interactive( 1 ); // makes an alert dialog from a button without this
            errText = Log Capture( p = Parse JSON( "\!n" /* invalid json error */ ) ); // writes to the log without this
            Batch Interactive( birestore ); // pop the previous behavior
            If( Length( errText ), Throw( "Caught an error:" || char(errText) ) ); // handle unexpected error, somehow
            /* use p here */
        )
    )
);

Suggestion: add an optional parameter to change the behavior, something like parseJson(x, throwIfError() )

Failsafe JSON parsing