473,320 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

What the heck is wrong with this JSON??

{"POINTID":77902,"MAPID":762,"LONG":-122.21654892,"LAT":"37.1834331019","CITY":"Boulder
Creek","STATE":"CA","DIST":5745.4}

I get an "invalid label" error...

I'm kinda new to this. Thanks!

Jul 12 '06 #1
5 10783

Ryan wrote:
{"POINTID":77902,"MAPID":762,"LONG":-122.21654892,"LAT":"37.1834331019","CITY":"Boulder
Creek","STATE":"CA","DIST":5745.4}

I get an "invalid label" error...

I'm kinda new to this. Thanks!
You're creating an object literal, in which could contain name value
pairs. The "invalid label" that you're seeing is from using incorrect
syntax.

Names have certain rules, for example, names cannot be any of reserved
keywords, cannot start with a number, and can not include special
characters, except an underscore or dollar sign.

Values can be a string, number, object, array, boolean, or null.

For a solution to your problem, this would be a fix: (formatted for
readability)

{POINTID: 77902,
MAPID: 762,
LONG: -122.21654892,
LAT: 37.1834331019,
CITY: "Boulder Creek",
STATE: "CA",
DIST: 5745.4}

Jul 12 '06 #2

Ryan wrote:
{"POINTID":77902,"MAPID":762,"LONG":-122.21654892,"LAT":"37.1834331019","CITY":"Boulder
Creek","STATE":"CA","DIST":5745.4}

I get an "invalid label" error...
>From a syntax point of view, nothing. You may have a new line
character or something that is breaking it in your actual code (note
that autowrapping in Google Groups has introduced one). Try
re-formatting it:

var s = {
"POINTID":77902,
"MAPID":762,
"LONG":-122.21654892,
"LAT":"37.1834331019",
"CITY":"Boulder Creek",
"STATE":"CA",
"DIST":5745.4
};

var t = [];
for (p in s){
t.push(p + ' : ' + s[p]);
}

alert(t.join('\n'));
--
Rob

Jul 12 '06 #3
web.dev wrote:
Ryan wrote:
>>
{"POINTID":77902,"MAPID":762,"LONG":-122.21654892,"LAT":"37.1834331019",
"CITY":"Boulder
>Creek","STATE":"CA","DIST":5745.4}

I get an "invalid label" error...

I'm kinda new to this. Thanks!

You're creating an object literal, in which could contain name
value pairs. The "invalid label" that you're seeing is from
using incorrect syntax.
Although some browser error messages seem obscure they often actually
provide a better clue to what is happening that it may at first appear.
In this case "invalid label" is a better clue than it appears as in
javascript/ECMAScript a label is used to identifier a point in the code
(expected to correspond with the start of a loop construct of some sort)
and consists of an Identifier followed by a colon. If an object literal
was interpreted in a context where what was intended to be a property
name in the form of a string literal was interpreted as a label (because
of the following colon) then it would be invalid and "invalid label"
would be a very direct and informative error message.

The problem here is likely that a string containing this apparent object
literal definition is begin passed directly to the - eval - function and
so is being interpreted as an entire javascript Program. The text of an
object literal definition in the wrong context can be interpreted as a
javascript Program. The surrounding braces become a Block statement, and
the contained name value pairs then look like labelled expression
statements. Under this interpretation most object literals would include
syntax errors and so fail to execute but some can happily (if
pointlessly) be executed as a javascirpt Program, e.g.:-

{
Anything: 555
}

- could happily be interpreted as a javascript Program; A block
statement surrounding a labelled expression statement consisting of a
number literal expression.

Indeed in the form above the 'object literal definition' cannot be
interpreted as an object literal as it commences with an opening brace,
which is explicitly forbidden as the starting token of an Expression
Statement.

For an object literal definition to be interpreted as an object literal
it needs to be unambiguously an expression. This can be done by an
action as simple as surrounding the object literal in parentheses (a
statement cannot be contained by the grouping operators, only an
expression may), or making the object literal the right hand side of an
assignment.
Names have certain rules, for example, names cannot be any
of reserved keywords, cannot start with a number, and can not
include special characters, except an underscore or dollar sign.
This is not true. Identifiers must follow these rules but property names
can consist of any arbitrary sequence of zero or more characters. This
is manifest in the object literal syntax by allowing Identifiers, string
literals and numeric literals to be used as the names of the name/value
pairs (though Mac IE 5 goes belly up if you try to use numeric literals
in that context). The quoted property names above are completely legal,
and probably represent an automated process wrapping the property names
in quotes so that it does not have to think about whether they would
qualify as Identifiers (though making them string literals would still
require the escaping of characters like line terminators).
Values can be a string, number, object, array, boolean, or null.
Or undefined, or functions, regular expressions, dates, etc (if a
distinction is to be drawn between arrays and objects).
For a solution to your problem, this would be a fix: (formatted for
readability)

{POINTID: 77902,
MAPID: 762,
LONG: -122.21654892,
LAT: 37.1834331019,
CITY: "Boulder Creek",
STATE: "CA",
DIST: 5745.4}
If the error had been - expected } or : - then maybe, but this chance
may make the label valid but will then move the error further down the
code to where the second colon is out of place in on expression in a
list expression.

Richard.
Jul 12 '06 #4
On Wed, 12 Jul 2006 14:58:15 -0700, Ryan wrote:
{"POINTID":77902,"MAPID":762,"LONG":-122.21654892,"LAT":"37.1834331019","CITY":"Boulder
Creek","STATE":"CA","DIST":5745.4}
Boulder Creek? Cool dude.
Excellent beer.

--
The USA Patriot Act is the most unpatriotic act in American history.
Feingold-Obama '08 - Because the Constitution isn't history,
It's the law.

Jul 13 '06 #5
Thanks for all the feedback. I found the fix, and I think it's related
to Richard's comments.

I *was* passing that explicit string to eval() and getting "invalid
label". What I found was that by enclosing the string with "(" and ")",
it worked.

I'll have to spend a bit of time re-reading what your explanation was,
but this fixed the problem.

Thanks!

Ivan Marsh wrote:
On Wed, 12 Jul 2006 14:58:15 -0700, Ryan wrote:
{"POINTID":77902,"MAPID":762,"LONG":-122.21654892,"LAT":"37.1834331019","CITY":"Boulder
Creek","STATE":"CA","DIST":5745.4}

Boulder Creek? Cool dude.
Excellent beer.

--
The USA Patriot Act is the most unpatriotic act in American history.
Feingold-Obama '08 - Because the Constitution isn't history,
It's the law.
Jul 13 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mike Henley | last post by:
I first came across rebol a while ago; it seemed interesting but then i was put off by its proprietary nature, although the core of the language is a free download. Recently however, i can't...
10
by: Greener | last post by:
Hi, I need help badly. Can you do client-side programming instead of server-side to capture the Browser type info? If this is the case, what's wrong with the following? <script...
6
by: Rtritell | last post by:
Please can you find out what's wrong, fix the script and tell me what was wrong. Im just beginning <html> <head> <title>Random Mad Lib!</title> <script language="JavaScript"> <!-- Hide
51
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
8
by: DJ | last post by:
What is wrong? #include <stdio.h> #define N 8 void order(int *p, int *q); int main(void)
10
by: Protoman | last post by:
Could you tell me what's wrong with this program, it doesn't compile: #include <iostream> #include <cstdlib> using namespace std; class Everything { public: static Everything* Instance()
12
by: questions? | last post by:
I am testing a problem with linked list. I just do a lot of times: create a list, then free it. ############################################# # include <stdio.h> # include <stdlib.h> struct...
9
by: Pyenos | last post by:
import cPickle, shelve could someone tell me what things are wrong with my code? class progress: PROGRESS_TABLE_ACTIONS= DEFAULT_PROGRESS_DATA_FILE="progress_data" PROGRESS_OUTCOMES=
2
by: eggie5 | last post by:
Is this JSON valid? I would like to access it like this in my javascript: var json=eval ('('+json+')'); json.devices.modelNumber and json.devices.image Would this work?
2
by: mingke | last post by:
Hi... So I have problem with my if condition..I don't know what's wrong but it keeps resulting the wrong answer.... So here's the part of my code I have problem with: for (i=0; i<size2;...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.