Reputation: 15770
Folks, I have a function that creates an Object that I would like to return back to the browser. For some reason, the browser is getting an empty Object without the contents:
{
pName: [ ]
}
Here is the object via console.log(require('util').inspect(projectObject, false, 10));
{ pName:
[ foo:
[ nodejs:
[ staging:
[
{ name: 'i-4a14c51a', id: 'i-4a14c51a' },
{ name: 'i-19fc094a', id: 'i-19fc094a' },
],
production:
[
{ name: 'i-5f14c50f', id: 'i-5f14c50f' },
{ name: 'i-b1fb0ee2', id: 'i-b1fb0ee2' },
]
]
],
...
I would imagine the reason its not returning the object is because it thinks that the first entity is empty.
Where am I making the mistake? The result needs to look liks:
"hosts": [
{
"projectA": [
{
"foo": [
{
"nodejs": [
{
"production": [
{
"name": "Her blog",
"cmd": "ssh [email protected]"
}
]
}
]
}
]
}
]
},
]
Upvotes: 1
Views: 1604
Reputation: 6665
I believe your problem is here:
{ pName:
[ foo: // <-- invalid JSON
[ nodejs:
[ staging:
...
If that's the output of an inspector I'd have a look at exactly how the projectObject
is being constructed (are you creating an array and then assigning something to a property on it? In which case create an object instead).
I'm afraid I'm not sure how I'm expected to get to the requested result with the information available however.
Upvotes: 2