Git Product home page Git Product logo

Comments (2)

CrowdHailer avatar CrowdHailer commented on May 14, 2024 1

For building arbitrary JSON data, a functional interface is probably best. e.g.

import jason.{object, string, boolean}
let body = jason.encode(
    object(
      [
        tuple("id_token", string(id_token)),
        tuple(
          "userinfo",
          object(
            [
              tuple("sub", string(email_address)),
              tuple("email", string(email_address)),
              tuple("email_verified", boolean(True)),
            ],
          ),
        ),
      ],
    ),
  )

This is extensible with your own types, for example dates etc.
Also for simplicity I think the return value from object should be the same as the return value from a decode function.

Certainly the above is similar in complexity to building with types. but it is cheaper, less intermediate data structures and with the benefit of extensibility.

  JsonObject(
    [
      tuple("id_token", JsonString(id_token)),
      tuple(
        "userinfo",
        JsonObject(
          [
            tuple("sub", JsonString(email_address)),
            tuple("email", JsonString(email_address)),
            tuple("email_verified", JsonBool(True)),
          ],
        ),
      ),
    ],
  ),

And is conceptually simpler to building your own dynamic data structures.

  let body = jason.encode(
    dynamic.from(
      map.from_list(
        [
          tuple("id_token", dynamic.from(id_token)),
          tuple(
            "userinfo",
            dynamic.from(
              map.from_list(
                [
                  tuple("sub", dynamic.from(email_address)),
                  tuple("email", dynamic.from(email_address)),
                  tuple("email_verified", dynamic.from(True)),
                ],
              ),
            ),
          ),
        ],
      ),
    ),
  )

from midas.

CrowdHailer avatar CrowdHailer commented on May 14, 2024

I will consider this done enough for milestone 0.2.0 the readme in gleam_jsone is enough information for now. However a general input parsing would be good, something that worked equally on querys form data and json.

from midas.

Related Issues (20)

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.