-1

Can someone figure out, why I get this error when I try to append a key/value to this JSON object?

$ node t.js 
undefined:1
[object Object]
 ^

SyntaxError: Unexpected token o in JSON at position 1

t.js

const toml = require('./toml');
const moment = require('moment');    
const t = toml('./non-production.toml');

let a = new Object;
a = JSON.parse(t.Jira.pack.c);

const time = moment().format("YYYY-MM-DDTHH:mm:ss.SSSZZ");
a["customfield_11904"] = time;

console.log(JSON.parse(a));

toml.js

const TOML = require('@iarna/toml');
const fs = require('fs');

module.exports = (filename) => {
  return TOML.parse(fs.readFileSync(filename, 'utf-8'));
}

non-production.toml

[Jira]
  pack.c = '{ "project": { "key": "DEMO" }, "issuetype": { "id": 10002 }, "priority": { "id": "3" }}'
Sandra Schlichting
  • 25,050
  • 33
  • 110
  • 162

1 Answers1

1

a is an object and cannot be parsed with JSON.parse, use console.log(a) instead

n--
  • 3,563
  • 4
  • 9