From b5547ccb58307f820f456024b737ee7a1bc3e236 Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Mon, 27 Jan 2025 21:26:47 -0500 Subject: [PATCH] Add getProperty method to JSON --- src/Parser/JSON.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Parser/JSON.md b/src/Parser/JSON.md index 60386ef..35f6312 100644 --- a/src/Parser/JSON.md +++ b/src/Parser/JSON.md @@ -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,