Friday, 12 May 2017

Convert JSON with objects and arrays to String

I have a JSON object which looks like this:

    {
        files: ['test.mp4'],
        name: ['testFile'],
        hints: ['%YES%_%MAYBE%_%NO%']
    }

And I need to convert it to a String so the output looks like this:

[{files=test, name=testFile, hints= %YES%_%MAYBE%_%NO%}]

Is this possible to achieve in Node JS? Thanks

I tried the following:

var x = {
    files: ['test.mp4'],
    name: ['testFile'],
    hints: ['%YES%_%MAYBE%_%NO%']
}
console.log(JSON.stringify(x));

But the output looks like this:

{"files":["test.mp4"],"name":["testFile"],"hints":["%YES%_%MAYBE%_%NO%"]}

Still with the square brackets. I may not 100% know the keys and values in the object above.



via deeveeABC

No comments:

Post a Comment