Help me understand this JSON eval problem please

R

ray_usenet

Why is this:

eval('[{\"active":"true"}]')

is OK, but

eval('{"active":"true"}') tells me I'm missing ";" ?

Then why is it that if I put parentheses around the second statement:

eval('({"active":"true"})')

Then it's OK again?

Thanks in advance!
Ray
 
R

Richard Cornford

Why is this:

eval('[{\"active":"true"}]')

is OK, but

eval('{"active":"true"}') tells me I'm missing ";" ?

Then why is it that if I put parentheses around the second statement:

eval('({"active":"true"})')

Then it's OK again?

A javascript Expression Statement may not commence with an opening
brace, so that it cannot be ambiguous along side Block Statements. The
- eval - function is supposed to execute a string as if it satisfied
the production rules for a Program, and Programs are made up of
statements, so - eval - must see the first opening brace and starting a
Block statement, and then the absence of a semicolon before the colon
is a syntax error. With the parentheses the opening brace is becomes
part of a parenthesised Expression and so must be interpreted as the
start of an object literal, and the parenthesised Expression becomes an
Expression Statement (as no other production can put an opening
parenthesis at the start of a Statement).

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top