2.x JSON Parser - Error handling and Defaults #2534
danbo
started this conversation in
User Support
Replies: 1 comment 1 reply
-
Excellent question. For now, I don't think that you can pass inline default values. You can, however, parse something as optional and then give it a default value: let json.parse ({foo, bla} : {foo: int, bla: string?}) = '{"foo":123}'
- : unit = ()
let bla = bla ?? "default"
- : unit = ()
bla
- : string = "default" |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
https://www.liquidsoap.info/doc-dev/json.html
I'm looking at supplying default values when a parse fails I'm not sure if that's currently possible with the new parser, it doesn't understand if I give defaults in the fields or type annotations:
What is the best way to handle this? It's not clear in the documentation. The only thing I can think of is using a try/catch, but then I have additional code to assign fallback values through ref assignments.
Beta Was this translation helpful? Give feedback.
All reactions