Add getProperty method to JSON

This commit is contained in:
Nathan McCarty 2025-01-27 21:26:47 -05:00
parent e91db14c11
commit b5547ccb58

View file

@ -108,6 +108,18 @@ dFoldL f acc (VBool b) = f acc _ (VBool b)
dFoldL f acc VNull = f acc _ VNull
```
Look up a property in an object
```idris
export
getProperty : (prop : String) -> (object : JSONValue TObject)
-> Maybe (type : JSONType ** JSONValue type)
getProperty prop (VObject xs) =
case dFind (\_, (key, _) => key == prop) xs of
Nothing => Nothing
Just (type ** (_, val)) => Just (type ** val)
```
## Parsers
We are going to get mutually recursive here. Instead of using a `mutual` block,