-
Can somebody help and describe how to add JSON to a collection with the Local API using the PostgreSQL backend? I've set up a field in a collection using Collection "Maps": export const Maps: CollectionConfig = {
fields: [
{
name: 'map',
type: 'json',
required: false,
},
... seed.ts: const map: Map = {
id: 0,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
slug: "some_slug",
title: "Some Title",
description: "Some Description",
map: JSON.parse(fs.readFileSync(dir + '/' + data.mapFile, 'utf-8')),
}
...
await payload.create({
collection: collection,
data: map,
}) Console log just before
DB (via psql):
edit: typo and added console.log on map object |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Well, my mistake. The above actually works. The problem in my case was a typo in another Here is the more complex example using a
seed.ts: const map: Map = {
...
maps: [
{
format: "format1",
map: JSON.parse(fs.readFileSync(dir + '/' + data.mapFile1, 'utf-8')),
},
{
format: "format2", // <- using a wrong option like 'format3' silently ignoring the insert and results in an empty DB column
map: JSON.parse(fs.readFileSync(dir + '/' + data.mapFile2, 'utf-8')),
},
],
} |
Beta Was this translation helpful? Give feedback.
Well, my mistake. The above actually works.
The problem in my case was a typo in another
select
field of the collection that had a wrong/not supported option. After fixing the typo, the JSON is correctly stored in the DB. It would be helpful though, if the local api would thrown an error instead of silently ignoring this.Here is the more complex example using a
json
and theselect
field within anarray
:Collection
maps
: