https://github.com/velveteer/json-mask
A Haskell library to filter JSON fields inspired by Google's Partial Response
https://github.com/velveteer/json-mask
google haskell json partial-responses
Last synced: about 1 month ago
JSON representation
A Haskell library to filter JSON fields inspired by Google's Partial Response
- Host: GitHub
- URL: https://github.com/velveteer/json-mask
- Owner: velveteer
- License: mit
- Created: 2024-03-18T02:05:01.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-22T03:40:06.000Z (about 2 years ago)
- Last Synced: 2025-12-26T02:59:07.525Z (6 months ago)
- Topics: google, haskell, json, partial-responses
- Language: Haskell
- Homepage:
- Size: 340 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
json-mask
A simple library for filtering JSON using the `fields` syntax inspired by Google's [Partial Response](https://developers.google.com/slides/api/guides/performance#partial). Field masks remove unnecessary values while retaining the structure of the JSON resource.
## Mask Syntax
* `a,b,c` comma-separated list will select multiple fields
* `a/b/c` path will select a field from its parent
* `a(b,c)` sub-selection will select many fields from a parent
* `a/*/c` the star `*` wildcard will select all items in a field
Terminal characters `,*()/` can be escaped using a single backslash `\`.
## Usage
```haskell
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.QQ.Simple as Aeson
import qualified Data.ByteString.Lazy as BSL
import JSONMask (masked)
val :: Aeson.Value
val = [Aeson.aesonQQ|{"p":{"a":1,"b":2},"z":1}|]
main :: IO ()
main = BSL.putStr . Aeson.encode $ masked val "p/a,z"
-- {p: {a: 1}, z: 1}
```
More examples can be found in the tests.