jsonb field not showing up in SHOW/EDIT
Describe the bug A clear and concise description of what the bug is.
Installed libraries and their versions
- [email protected]
- [email protected]
- @admin-bro/sequelize
To Reproduce
Steps to reproduce the behavior:
I am trying to display and enable edit for one of my models that has a JSONB datatype.
instructor model
const Instructor = sequelize.define('Instructor', {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true
},
submission: {
type: DataTypes.JSONB,
allowNull: false
},
}, {});
resource definition
const adminBro = new AdminBro({
resources: [{resource: Provider}, {
resource: Instructor,
options: {
properties: {
submission: {
type: 'mixed',
show: true,
filter: false,
edit: true
},
},
}
}],
})
const router = AdminBroExpress.buildRouter(adminBro)
app.use(adminBro.options.rootPath, router)
Here is the UI result in admin:

Expected behavior should display json data and be able to edit it.
[email protected]
[email protected]
@admin-bro/sequelize
v2.0.1 is very old - AFAIK it didn't even support JSONB objects/arrays, have you tried updating? If you decide to update, it's best to update to admin-bro@beta until it's promoted to official version. It's stable/safe to use if you are worried since most of the changes are actually bug fixes.
If you update to >=v3, make sure to use @admin-bro/express package instead of admin-bro-expressjs.
Strange... I'm mistaken about my version here is the version i currently have, still doesn't show me/let me edit json field:
"admin-bro": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/admin-bro/-/admin-bro-3.4.0.tgz",
...
"@admin-bro/design-system": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/@admin-bro/design-system/-/design-system-1.7.0.tgz",
...
"@admin-bro/express": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/@admin-bro/express/-/express-3.1.0.tgz",
},
"@admin-bro/sequelize": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/@admin-bro/sequelize/-/sequelize-1.2.1.tgz",
Could you please try updating to v4? JSONB handling was bugged but the fix should be included there. Just run yarn add admin-bro@latest or npm i admin-bro@latest
However you have to define available keys yourself, i. e.:
properties: {
submission: {
type: 'mixed',
},
'submission.someField': { type: 'string' },
'submission.anotherField': { type: 'number' },
},
Currently it isn't possible to add extra keys in the UI so they have to be predefined.
ok what if they are nested objects?
example of a submission field value:
'submission': {
'element': {
'type': 'button',
'attr': 'class',
'value': 'ta-button',
'event': 'click'
}
},
submission: { type: 'mixed' },
'submission.element': { type: 'mixed' },
'submission.element.type': { type: 'string' },
'submission.element.attr': { type: 'string; },
...etc
Similarly for arrays, i.e.
items: { type: 'mixed', isArray: true },
If you want to have an array of i. e. { label: 'string', value: 'number' }:
'items.label': { type: 'string' },
'items.value': { type: 'number' },
I've also recently added isDraggable option which works if isArray is true:
items: { type: 'mixed', isArray: true, isDraggable: true },
It allows you to reorder elements in JSONB arrays
Great, thank you @dziraf! i'll try that
It would be interesting to have admin-bro automatically traverse the json and builds the necessary fields. I would say maybe it would be better to just output the json object and make that editable.
submission: { type: 'mixed' }, 'submission.element': { type: 'mixed' }, 'submission.element.type': { type: 'string' }, 'submission.element.attr': { type: 'string; }, ...etcSimilarly for arrays, i.e.
items: { type: 'mixed', isArray: true },If you want to have an array of i. e.
{ label: 'string', value: 'number' }:'items.label': { type: 'string' }, 'items.value': { type: 'number' },I've also recently added
isDraggableoption which works ifisArrayistrue:items: { type: 'mixed', isArray: true, isDraggable: true },It allows you to reorder elements in JSONB arrays
@dziraf This helped a lot, but can you also elaborate how an Json Array of strings in DB can be configured manually?
Fo example:
items: ['asd', 'abc', 'cad] so what I understand we can just do items: { type: 'mixed', isArray: true } but how do I define the array property types?
In my case i don't have predefined structure for json. How can I show this?
In my case i don't have predefined structure for json. How can I show this?
I am exactly in this situation: a JSON field with an arbitrary structure, and AdminJS won't show it nor allow editing it, and there is no workaround that I could find. Just editing the JSON as a string would suffice, I don't need anything more user-friendly.
One would think that the most common case for a JSON field in a SQL database is to have arbitrary data, because if you have a predefined structure then you would use table columns for them.