Coder Social home page Coder Social logo

percyqaz.data's Introduction

Percyqaz.Data

Has expanded from its original purpose from a JSON mapping library, so I've updated the name to Percyqaz.Data
I am too lazy to update documentation right now (given that only my projects depend on this), but below is the README from a couple years ago


Percyqaz.Json

Yet another JSON library, specificially for my F# JSON needs which were not met by JSON.Net or Chiron

How it works:

  1. Parsing and writing:
    • JSON text is parsed using FParsec into an F# discriminated union/tree.
    • The tree can be formatted back as valid JSON text.
  2. Encoding and decoding:
    • Each type has a hand-made codec that maps between it and the JSON tree.
  3. Ease of use:
    • Many important codecs are ready out-of-the-box.
    • It is simple to hand-write your own codecs for types.
    • Records and DUs can be tagged with an attribute to auto-generate a codec.

Key design principles

  • No care for how the outputted JSON text is formatted (validity is the only concern)
  • Null-safety: You can't deserialise JSON to get null for non-nullable F# objects etc
  • Support for all simple F# types out-of-box
  • Simple code: Exceptions are thrown internally instead of railroading/result types
  • Easily extensible: You can add codecs for types as you need

Getting started

You can get this package on NuGet

DOCUMENTATION IS CURRENTLY OUTDATED FOR VERSION 3.0

IM LAZY AND ALSO NOBODY IS ACTIVELY USING THIS SO NOT A PRIORITY

You should read the documentation here (it's not long)

percyqaz.data's People

Contributors

percyqaz avatar 9382 avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

9382

percyqaz.data's Issues

Support for Value Options

Typeshape doesn't have a FSharpValueOption recogniser
will look into making an issue/writing my own solution here/writing my solution as a PR for typeshape

for now Value Options use the default Struct Union codecs

v3 of Json

Codec<'T> has To and From method

Use reflection to find an appropriate codec

Cache the codec members as delegates for performance

Benchmark

Support for F# Sets

currently unable to reuse the 'T list or 'T array codecs due to compiler not knowing if 'T : comparison

Bigger test coverage

Here's what needs to be covered

  • Basic round trips for all the default rules (including float edge cases)

  • Performance benchmarks once codecs are cached for small, medium, large objects

  • Intended decode-time fail cases (null strings, null arrays, missing required properties in records, etc)

  • Intended cache-time fail cases (no codec rule, invalid JsonCodec member)

  • Round trips when implementing custom rules

  • Basic API stuff (IO exceptions, etc)

Require attribute indicating no default record provided?

Most recent change removes the need for a Default implementation of records but now

  • Records will now magically serialise in unplanned ways, for example you may make a typo in Default or otherwise believe you have given default values when you have in fact not.
  • This assumes all members of the record do not need an original value when deserialising. While true for most things this may not be true for user defined deserialisation.
    • This also sparks an issue of marking user defined serialisation with "Expecting a non-null instance" but an idea on how to neatly design this hasn't come to me yet

Suggested fix: Make not having a default an attribute. Then at pickler-creation-time mistakes are caught instead of later down the line

Complete Record auto codec behaviour

  • Flag "RequireAll" true means all props are non-optional
  • Flag "RequireAll" false means anything missing in json data can be filled with defaults
  • Default property used to provide defaults (otherwise use normal defaults)

Recursive type support

Recursive types hang because there needs to be indirection when constructing the codecs

Thread safety

Access to API needs to be concurrent safe - Maybe just use a concurrent dictionary as it's the only shared state

Codec combinator system

a handful of combinators for easy building of hand-made codecs for records would be nice

can probably take inspiration from chiron/fleece which are entirely this approach

Rewrite JSON to use less memory

  • Replace intermediary JSON AST with a structure that reads through a stream and enumerates JSON nodes
  • Replace serialisation with a structure that writes JSON nodes to a stream
  • Replace all existing reader/writer logic

In short instead of parsing entire 100mb files of JSON into X mb of JSON-typed structures in memory, then transforming that into X mb of F# objects, scan the 100mb in as a stream and read objects out as you go

Error handling

Error midway through serialising -> What happens?

  • Way to just end/cut short any open JSON nodes so the file is well formed
  • Tell users not to throw exceptions in their serialisers

Whats the point of doing it if this is literally how System.Text/Newtonsoft works

Fun

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.