Popularity
6.2
Stable
Activity
0.0
Stable
11
7
0
Monthly Downloads: 22
Programming language: Haskell
License: MIT License
Latest version: v0.4.0.0
highjson alternatives and similar packages
Based on the "json" category.
Alternatively, view highjson alternatives based on common mentions on social networks and blogs.
CodeRabbit: AI Code Reviews for Developers
Revolutionize your code reviews with AI. CodeRabbit offers PR summaries, code walkthroughs, 1-click suggestions, and AST-based analysis. Boost productivity and code quality across all major languages with each PR.
Promo
coderabbit.ai
Do you think we are missing an alternative of highjson or a related project?
README
highjson
Intro
Hackage: highjson
Low boilerplate, easy to use and very fast Haskell JSON serialisation and parsing without the help of TemplateHaskell or Generics built on top of aeson.
Usage
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PartialTypeSignatures #-}
import Data.Aeson
import Data.HighJson
import Data.HighJson.Swagger -- optional
import Data.Swagger -- optional
data SomeDummy
= SomeDummy
{ sd_int :: Int
, sd_bool :: Bool
, sd_text :: T.Text
, sd_either :: Either Bool T.Text
, sd_maybe :: Maybe Int
} deriving (Show, Eq)
someDummySpec :: RecordTypeSpec SomeDummy _
someDummySpec =
recSpec "Some Dummy" Nothing SomeDummy $
"int" .= sd_int
:& "bool" .= sd_bool
:& "text" .= sd_text
:& "either" .= sd_either
:& "maybe" .= sd_maybe
instance ToJSON SomeDummy where
toJSON = jsonSerializer someDummySpec
toEncoding = jsonEncoder someDummySpec
instance FromJSON SomeDummy where
parseJSON = jsonParser someDummySpec
instance ToSchema SomeSum where -- optional, generates swagger2 specifications
declareNamedSchema p = makeDeclareNamedSchema someDummySpec p
test =
decodeEither "{\"int\": 34, \"text\": \"Teext\", \"bool\": true}"
== Right (SomeDummy 34 True "Teext" Nothing)
Template haskell
There's also a small shortcut via template haskell (highjson-th
):
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
import Data.HighJson
import Data.HighJson.Swagger
import Data.HighJson.TH
data SomeDummy
= SomeDummy
{ sd_int :: Int
, sd_bool :: Bool
, sd_text :: T.Text
, sd_either :: Either Bool T.Text
, sd_maybe :: Maybe Int
} deriving (Show, Eq)
someDummySpec :: RecordTypeSpec SomeDummy _
someDummySpec =
recSpec "Some Dummy" Nothing SomeDummy $
"int" .= sd_int
:& "bool" .= sd_bool
:& "text" .= sd_text
:& "either" .= sd_either
:& "maybe" .= sd_maybe
$(deriveJsonSwagger ''SomeDummy 'someDummySpec)
test =
decodeEither "{\"int\": 34, \"text\": \"Teext\", \"bool\": true}"
== Right (SomeDummy 34 True "Teext" Nothing)
Tests
For more usage examples check the tests.
Install
- Using cabal:
cabal install highjson
- From Source:
git clone https://github.com/agrafix/highjson.git && cd highjson && cabal install
Benchmarks
There are benchmarks in the project and it is expected to be en par or faster than aeson
s generic instances.