GithubHelp home page GithubHelp logo

Generate objects from JSON about remodel HOT 6 CLOSED

facebook avatar facebook commented on July 27, 2024
Generate objects from JSON

from remodel.

Comments (6)

ColinCampbell avatar ColinCampbell commented on July 27, 2024

In terms of creating instances of objects in your application, or fetching JSON from an endpoint and using that to generate objects using Remodel?

from remodel.

avnerbarr avatar avnerbarr commented on July 27, 2024

from remodel.

ColinCampbell avatar ColinCampbell commented on July 27, 2024

@avnerbarr there's no built-in support for parsing JSON objects in Remodel objects, but it would be relatively straight-forward to write a plugin that would do that for you, depending on if you need to add support for nested object types. Could you provide a sample response?

from remodel.

avnerbarr avatar avnerbarr commented on July 27, 2024

I have a very complex JSON with lots of nesting but in general it could be something like

[
  {
    "_id": "586bc0e867eb88690303b838",
    "index": 0,
    "guid": "1a69dde7-59f3-4daf-8f94-76e168f71a4d",
    "isActive": false,
    "balance": "$1,496.45",
    "picture": "http://placehold.it/32x32",
    "age": 25,
    "eyeColor": "green",
    "name": "Julia Ford",
    "gender": "female",
    "company": "COMVEYOR",
    "email": "[email protected]",
    "phone": "+1 (857) 580-2018",
    "address": "416 Oriental Boulevard, Skyland, Tennessee, 3208",
    "about": "Lorem aute fugiat sunt sint magna qui et laboris. Aute ut ad ipsum cupidatat culpa ea sit cillum. Laborum irure id proident pariatur non nulla Lorem anim enim id voluptate deserunt aute dolor. Lorem ullamco deserunt laboris aliqua pariatur ex id. Mollit labore ea nostrud exercitation est culpa anim ea enim. Nisi reprehenderit ad ullamco do aliqua ea culpa cillum consectetur eu id amet ad.\r\n",
    "registered": "2015-02-13T10:05:01 -02:00",
    "latitude": -65.19895,
    "longitude": -95.259513,
    "tags": [
      "duis",
      "reprehenderit",
      "deserunt",
      "fugiat",
      "quis",
      "aliquip",
      "elit"
    ],
    "friends": [
      {
        "id": 0,
        "name": "Lorena Day"
      },
      {
        "id": 1,
        "name": "Vanessa Pratt"
      },
      {
        "id": 2,
        "name": "Bridget Willis"
      }
    ],
    "greeting": "Hello, Julia Ford! You have 3 unread messages.",
    "favoriteFruit": "banana"
  }
]

from remodel.

andrewcuneo avatar andrewcuneo commented on July 27, 2024

@avnerbarr, this is an ideal use case for a plugin.

If you check out the section in this document called "Customizing Remodel", you can find a rough example of building a plugin.

Also, this document has more thorough information about the mechanics of setting one up.

from remodel.

calimarkus avatar calimarkus commented on July 27, 2024

Here's a basic JSON plugin, that let's you both

  • create an object from a JSON dictionary and
  • create a JSON dictionary from an object

https://gist.github.com/calimarkus/c4287bea1a7ae5a9e2ebcd53d93e5c12

This is not tested in any way and thus not production ready.
Take it as a starting point to write your own plugin.
It also doesn't support nested objects in its current state.

from remodel.

Related Issues (19)

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.