Git Product home page Git Product logo

idris2-json's Introduction

idris2-json

Automatically derivable JSON marshallers in the spirit of Haskell's aeson.

Please note, that while tests suggest that the encoders and decoders perform reasonably well, this library has not been optimized in terms of performance.

Usage Example

Getting started with encoding and decoding is very easy:

module README

import JSON.Derive

%language ElabReflection

data MonsterClass = Imp | Goblin | Orc | Dragon

%runElab derive "MonsterClass" [Show,Eq,ToJSON,FromJSON]

record Villain where
  constructor MkVillain
  name    : String
  hp      : Nat
  class   : MonsterClass
  cronies : List Villain

%runElab derive "Villain" [Show,Eq,ToJSON,FromJSON]

gorgar : Villain
gorgar = MkVillain "Gorgar" 2000 Dragon [MkVillain "Igor" 10 Imp []]

You can give this a try at the REPL:

pack repl docs/src/README.md

README> :exec putStrLn $ encode gorgar
README> :exec printLn $ (decode {a = Villain} (encode gorgar))

More examples can be found in the tutorial.

Dependencies

Besides base, the following dependencies are needed to support the automatic deriving of interface implementations:

In addition, the test suit requires the following:

It is nowadays recommended to use a package manager such as pack for installing and managing your Idris2 dependencies.

The json-simple sub-project

Personally, I don't think the versatility of using different JSON representations and thus having to go via Encoder, Value, or Object interfaces is worth the hassle. I therefore added a second library, which uses just the JSON representation from the parser-json package.

idris2-json's People

Contributors

stefan-hoeck avatar mattpolzin avatar victor-savu avatar kbertalan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.