473,699 Members | 2,231 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What the heck is wrong with this JSON??

{"POINTID":7790 2,"MAPID":762," LONG":-122.21654892,"L AT":"37.1834331 019","CITY":"Bo ulder
Creek","STATE": "CA","DIST":574 5.4}

I get an "invalid label" error...

I'm kinda new to this. Thanks!

Jul 12 '06 #1
5 10805

Ryan wrote:
{"POINTID":7790 2,"MAPID":762," LONG":-122.21654892,"L AT":"37.1834331 019","CITY":"Bo ulder
Creek","STATE": "CA","DIST":574 5.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":7790 2,"MAPID":762," LONG":-122.21654892,"L AT":"37.1834331 019","CITY":"Bo ulder
Creek","STATE": "CA","DIST":574 5.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.18343 31019",
"CITY":"Bou lder 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":7790 2,"MAPID":762," LONG":-122.21654892,"L AT":"37.1834331 019",
"CITY":"Bou lder
>Creek","STATE" :"CA","DIST":57 45.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":7790 2,"MAPID":762," LONG":-122.21654892,"L AT":"37.1834331 019","CITY":"Bo ulder
Creek","STATE": "CA","DIST":574 5.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":7790 2,"MAPID":762," LONG":-122.21654892,"L AT":"37.1834331 019","CITY":"Bo ulder
Creek","STATE": "CA","DIST":574 5.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
2381
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 help but say i was totally impressed. I needed an open source wikiblog/wikilog, whatever you wanna call it, basically a hybrid of a blog and a wiki. I checked out snipsnap, which uses java, it was said on their site to be a clone of vanilla, a...
10
3404
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 language="JavaScript"> function doWord(file) { if (navigator.userAgent.indexOf("MSIE")!=-1)
6
2022
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
13363
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 wrong????? Function x select case z
8
279
by: DJ | last post by:
What is wrong? #include <stdio.h> #define N 8 void order(int *p, int *q); int main(void)
10
3227
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
1877
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 element { int index; struct element *next;
9
2122
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
1715
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
2233
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; i++){ for (k = 0; k < point3; k++){
0
8694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8621
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9041
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8890
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7757
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4634
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2355
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.