node-comment-json
node-comment-json copied to clipboard
Is it possible to insert a comment after a value?
After a json has been parsed, is it possible to insert a new comment that will then be retained? If so, how? I'm pulling my hair out...
I am also curious about this. Also i want to know how to add comments when building json object at runtime (not loading/parsing).
So for example i have this code:
const {stringify} = require('comment-json');
let obj = { name: "peter"; age: 20; };
// TODO: how to add comment before property "name" here before calling stringify ?
const str = stringify(obj);
@blhoward2 @kaelzhang I found a wacky way to do this (ugly but working):
obj[Symbol.for('before:name')] = [{type: 'LineComment', inline: false, value: 'my custom comment'}];
will stringify to:
{
// my custom comment
name: "peter";
age: 20;
};