Skip to content

A Haskell library to filter JSON fields inspired by Google's Partial Response

License

Notifications You must be signed in to change notification settings

velveteer/json-mask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json-mask

A simple library for filtering JSON using the fields syntax inspired by Google's Partial Response. 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

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.

About

A Haskell library to filter JSON fields inspired by Google's Partial Response

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published