Issue #3136✓ SolvedOpened November 11, 2020by vijaycreatise2 reactions

Create one more key in JSON

Quick answerby longdoan74212

Sorry I misunderstood your problem, so my previous comment was not relevant. To achieve your desire, you need create your own trait type (docs) and component type (docs). There is an easier way but it can not save all your custom data as an object to the data key. The JSON result would be like this: Sample code: You c...

Read full answer below ↓

Question

{ "type": "text", "status": "hovered", "content": "Insert your text here", "attributes": { "id": "ixx2" }, "activeOnRender": 0, "open": false } In JSON I want add new key with object. Example data key this will have custom Traits. I want to add new object from where data can be fetch and populate the output. Can I do this? Below is sample object how I wanted. Can any one help me on this how can I achieve this. { "type": "text", "status": "hovered", "content": "Insert your text here", "attributes": { "id": "ixx2" }, "data":{ "url":"https://something.com", "refresh_rate":"10" }, "activeOnRender...

Answers (4)

👍 Most helpfullongdoan7421November 12, 2020

Sorry I misunderstood your problem, so my previous comment was not relevant. To achieve your desire, you need create your own trait type (docs) and component type (docs). There is an easier way but it can not save all your custom data as an object to the data key. The JSON result would be like this...

longdoan7421November 11, 2020

I'm not sure if I get your problem.

But if you set any custom attributes to component model (except some preserve keys like components, styles, ...) e.g: component.set('customTraits', yourCustomTraits);. It would be in JSON data.

vijaycreatiseNovember 11, 2020

I tried like this, but it is not working. I want to add data key and object in JSON, when user select form they can enter API url. Can you please check am I doing correctly?

GJSBlockMay 17, 2026

Thanks for reporting this, @vijaycreatise. Great question about Create one more key in JSON. The recommended approach with GrapesJS is to use the event-driven API. Start here: Check the GrapesJS documentation for your specific module Look for the on() event listener method Most operations can be ac...

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.