frumbert frumbert - 1 year ago 58
JSON Question

Get json value as string?

Say I have an object

var BOB = {
"name": "bob",
"height": 185

And I have another object which references a value from it

var PROPS = {
"bob": {
"height": BOB.height

So now
will equal
. If I stringify the object, I get

{"bob": {"height": 185}}

Can I work out the string value of what was evaluated to return the value
. e.g. work out the source code from within the code ...:

var s = findOutTheSourceCode(PROPS);

// s would be
"bob": {
"height": BOB.height

Answer Source

In general, no. That information isn't stored anyway.

If the code was part of a function and you have a reference to that function and you are using a JS engine which supports this non-standard feature then you can call thatfunction.toString() and then try to find the relevant bit of code using (for example) pattern matching.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download