question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve JSON documentation & output

See original GitHub issue

I couldn’t find any examples of what the JSON format looked like, and I wanted to be sure the format was relatively independent of Craft itself. However, the JSON uses node IDs instead of nesting the nodes themselves, which I find confusing.

For example, with these Frame contents:

<Frame>
  <Canvas is={CraftContainer}>
    <CraftComponent>
      <TextComponent text="my text here" />
    </CraftComponent>
  </Canvas>
</Frame>

The JSON output from query.serialize() is:

{
  "canvas-ROOT": {
    "type": {
      "resolvedName": "CraftContainer"
    },
    "isCanvas": true,
    "props": {},
    "displayName": "Canvas",
    "custom": {},
    "nodes": [
      "node-yxVcZGJj"
    ]
  },
  "node-yxVcZGJj": {
    "type": {
      "resolvedName": "CraftComponent"
    },
    "props": {
      "children": [
        {
          "type": {},
          "props": {
            "text": "text component"
          }
        }
      ]
    },
    "displayName": "CraftComponent",
    "custom": {},
    "parent": "canvas-ROOT",
    "_childCanvas": {
      "d02fab54-ddf2-4356-b79d-5660d54915df": "canvas-u-wv625gX"
    }
  },
  "canvas-u-wv625gX": {
    "type": {
      "resolvedName": "CraftContainer"
    },
    "isCanvas": true,
    "props": {},
    "displayName": "Canvas",
    "custom": {},
    "parent": "node-yxVcZGJj",
    "nodes": [
      "node-aKYJYqPZ0"
    ]
  },
  "node-aKYJYqPZ0": {
    "type": {},
    "props": {
      "text": "my text here"
    },
    "displayName": "TextComponent",
    "custom": {},
    "parent": "canvas-u-wv625gX"
  }
}

I would expect something more like:

[
  {
    "type": "CraftContainer",
    "nodes": [
      {
        "type": "CraftComponent",
        "nodes": [
          {
            "type": "TextComponent",
            "props": {
              "text": "my text here"
            }
          }
        ]
      }
    ]
  }
]

It would also be nice to have some examples of implementing custom serializers, like SlateJS does. I’m currently using SlateJS as a WYSIWYG React editor, but I’d love to switch to Craft for the nicer drag & drop functionality.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:9
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
Hyperkid123commented, Jan 15, 2020

@hdaggett @prevwong I am intrigued by this library. A hierarchical output of the state would be really nice. I think it can be done in consumer libraries/apps, but I also think that for generating the UI from the state, the nested JSON would be a preferable format than a flat object.

I would love to try it out and use this library for a form builder component for dynamic form library we are developing using in our projects. So I am more than willing to create a PR with this feature if you haven’t started working on it yet.

1reaction
prateekrastogicommented, Jan 15, 2020

@hdaggett @Hyperkid123 PR is much needed herein

Read more comments on GitHub >

github_iconTop Results From Across the Web

11 Ways to Improve JSON Performance & Usage - Stackify
1. You may need multiple JSON libraries for optimal performance and features · 2. Use streams whenever possible · 3. Compress your JSON...
Read more >
How to improve performance of fetching data from JSON ... - IBM
Two items can improve the performance well to fetch data from JSON-based RESTful data source via Autonomous REST Connector. 1.
Read more >
Optimize JSON processing with in-memory OLTP - SQL Server
To increase the performance of queries that process JSON data, you can store JSON documents in memory-optimized tables using standard string ...
Read more >
Building a high performance JSON parser - Dave Cheney
Building a high performance JSON parser ... JSON is important, damn near everything that we do as programmers or operators involves JSON at...
Read more >
Blogger JSON API: Performance Tips - Google Developers
Another way to improve the performance of your API calls is by sending and receiving only the portion of the data that you're...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found