Miyako,

On Thu, Feb 1, 2018 at 12:33 PM, Keisuke Miyako via 4D_Tech <4d
[email protected]> wrote:

> I don't think that actually proves that JSON Parse is throwing the
> runtime error.
>
​Agreed. But that is where it shows up so it's the place to start.​


rather than looking at the "line of code referenced in the error dialog"
> perhaps you could activate debug log recording in verbose mode (2)
> at the start of the offending method (and disable it a the end)
>
> http://doc.4d.com/4Dv16R5/4D/16-R5/SET-DATABASE-PARAMETER.
> 301-3481818.en.html
>
> source code is stripped in a 4DC, so I wouldn't completely trust the line
> of code printing in the error dialog.
>
​Again, I agree and would do this is to track down an error.

But my fundamental question is how do I validate a string as something that
can be parsed before feeding it to JSON Parse where I'll get a runtime
error?​ That's really all I'm looking for. The solutions I'm finding so far
only work interpreted.


>
> how do you looks at the string to see if it begins with "{" or "[" ?
>
​I use a case statement like:

Case of

:(length($str)<2) ` a valid string could be 2 chars: {} or []

:($str[[1]]="{")

json parse

​:($str[[1]]="[")

json parse array...

End case


Perhaps a better threshold definition would help.
The smallest valid object is, I think: {"a":1} or seven chars.
​The smallest valid array would be  [1] or three chars. So​

Case of

:(length($str)<2) ` a valid string could be 2 chars: {} or []

:($str[[1]]="{")&;(Length($str)<7)`  not possible
:($str[[1]]="{")

json parse

​:($str[[1]]="[")

json parse array...

End case



> besides, you shouldn't have to look at the string in the first place if
> you use JSON Parse with error handling.
>
​I don't understand. ​How can I not look at the strings to see if they are
valid if I'm getting an error attempting to parse them? 4D's parser is
strict - it gags on strings with an extra comma for example:

{"a":1, "b":2,}  but not​
​  {"a":1, "b":2} ​

​I don't have a problem with it being strict I'm just trying to understand
how to protect against runtime errors in this instance. Clearly it's in the
data. But without a way to log the error it's hard to know where to start
looking. Especially when it's the server that gets blocked by one. ​

​Perhaps I'm not handling this sort of problem the way most folks do. If so
it's out of ignorance and not intransigence. I'm happy to be guided
otherwise.

-- 
Kirk Brooks
San Francisco, CA
=======================

We go vote - they go home
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to