473,786 Members | 2,571 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 10809

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
2384
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
3413
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
2024
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
13388
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
3237
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
1888
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
2124
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
1719
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
2235
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
9650
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
9497
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
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7515
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
6748
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
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...
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.