1

I have a JSON data which is getting generated through python scripts as below.

JSON:

{
"name":"abc"
"insrt_dt": datetime.datetime(2020,12,15,18,35,30,31547}
"demand_dt": Timestamp('2014-05-09 00:00:00')
}

I want to do schema validation before inserting it into Mongo database.

I am able to handle "name" field , but not able to handle "insrt_dt" & "demand_dt" fields. for name: it is working as per syntax.

json schema date-time does not check correctly.

but unable to decide type and format for "insrt_dt" & "demand_dt"

Raj N.
  • 13
  • 4

2 Answers2

0

the JSON needs to be correctly formatted. In particular, missing commas. also the datetime line was closed with } and should be ).

see: https://json.org/example.html

The correct JSON should look like this:

{
"name":"abc",
"insrt_dt": datetime.datetime(2020,12,15,18,35,30,31547),
"demand_dt": Timestamp('2014-05-09 00:00:00')
}
D.L
  • 4,339
  • 5
  • 22
  • 45
0
  import mongoose from 'mongoose';
  const { Schema } = mongoose;

  const blogSchema = new Schema({
    name: String,
    insrt_dt: { type: Date, default: Date.now },
    demand_dt: { type: Date, default: Date.now },
  });

// is Timestamp('2014-05-09 00:00:00') number ?

Daniil Loban
  • 4,165
  • 1
  • 14
  • 20