Skip to content

JSON type is broken for array. Array comes back as string. #2619

@thesunny

Description

@thesunny

Bug description

When you do a prisma.table.create or prisma.table.update with an array value, the array is converted to a serialized string.

How to reproduce

Based on a minimal schema on PostgreSQL:

model stories {
  id    Int    @id @default(autoincrement())
  title String
  tags  Json
}
import { PrismaClient } from "@prisma/client"

const prisma = new PrismaClient()

async function start() {
  const data = { title: "Cool", tags: ["Matrix", "Star Wars"] }
  const createStory = await prisma.stories.create({ data })
  console.log(createStory)
  console.log(typeof createStory.tags) // returns `string`
  const story = (await prisma.stories.findMany({ take: 1 }))[0]
  console.log(story)
  console.log(typeof story.tags) // returns `string`
}

start()

Array data in a JSON field is always serialized (i.e. turned into a string). For clarity, I have checked the database and in the database, the value is also a string.

image

string, number and object work okay.

Expected behavior

When you insert an array it should be returned as an array

Prisma information

Shared above

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL
  • Prisma version: Prisma 2, beta 7
  • Node.js version: 12.16.2

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions