Basic JSON question: Do I really need the quotes

M

moogyd

Hi,
I need to define some configuration in a file that will be manually created.
Internally, the data will be stored as a dict, which contains various properties related to a design
e.g. Design Name, dependencies, lists of files (and associated libraries).
json seemed a quick an easy way of achieving this
Anyway, in simple terms my question - if I know everything is a string, how can I omit the quotation marks?

i.e. I can do
json.loads('{"mykey":["data0", "data1"]}')
{u'mykey': [u'data0', u'data1']}

But I would like to do
json.loads('{mykey:[data0, data1]}')
Traceback (most recent call last):

The problem is that I don't want to make users have to type redundant characters.
Is it possible?
Thanks,
Steven
 
K

Kwpolska

Hi,
I need to define some configuration in a file that will be manually created.
Internally, the data will be stored as a dict, which contains various properties related to a design
e.g. Design Name, dependencies, lists of files (and associated libraries)..
json seemed a quick an easy way of achieving this
Anyway, in simple terms my question - if I know everything is a string, how can I omit the quotation marks?

Nope. JSON has those rules for a reason. You need to be specific. A
more “human-friendly†format is the one used by ConfigParser (close to
INI, but not quite).

Also, JSON is supposed to be generated by computers, not humans.
 
R

Roel Schroeven

(e-mail address removed) schreef:
Hi,
I need to define some configuration in a file that will be manually created.
Internally, the data will be stored as a dict, which contains various properties related to a design
e.g. Design Name, dependencies, lists of files (and associated libraries).
json seemed a quick an easy way of achieving this
Anyway, in simple terms my question - if I know everything is a string, how can I omit the quotation marks?

The problem is that I don't want to make users have to type redundant characters.
Is it possible?

Not in JSON. Maybe you could try YAML?

--
"Too often we hold fast to the cliches of our forebears. We subject all
facts to a prefabricated set of interpretations. Too often we enjoy the
comfort of opinion without the discomfort of thought."
-- John F Kennedy

(e-mail address removed)
 
A

Adam Tauno Williams

(e-mail address removed) schreef:
Not in JSON. Maybe you could try YAML?

If you want a human-readable human-editable markup for data structures I
strongly encourage you to look at YAML. JSON is not wetware friendly.
 
R

Roy Smith

I need to define some configuration in a file that will be manually created.
[...]
json seemed a quick an easy way of achieving this

JSON would not be my first choice for a file which needs to be
maintained by hand.

I've only recently started using a system that has YAML config files.
I've quickly become enamored of the format for config files. I don't
know if it's capable of expressing everything you can with JSON, but it
certainly can do anything you would reasonably want to put in a config
file, it's easy to read, and easy to hand-edit.
The problem is that I don't want to make users have to type redundant
characters.

I think what you're saying is, "My users would prefer YAML over JSON" :)
 
R

rusi

I need to define some configuration in a file that will be manually created.
[...]
json seemed a quick an easy way of achieving this

JSON would not be my first choice for a file which needs to be
maintained by hand.

I've only recently started using a system that has YAML config files.
I've quickly become enamored of the format for config files.  I don't
know if it's capable of expressing everything you can with JSON, but it
certainly can do anything you would reasonably want to put in a config
file, it's easy to read, and easy to hand-edit.

Yaml is a superset of json http://en.wikipedia.org/wiki/YAML#JSON

I find it a bit mysterious: yaml's structure-via-indentation
philosophy makes it more in line with python than most other modern
languages. And yet its the ruby community that seems to most eagerly
embrace yaml. Specially ironic given that ruby's syntax is reminiscent
of Pascal -- statements dont just close with '}' but with 'end'
 
M

moogyd

Hi,

I need to define some configuration in a file that will be manually created.

Internally, the data will be stored as a dict, which contains various properties related to a design

e.g. Design Name, dependencies, lists of files (and associated libraries).

json seemed a quick an easy way of achieving this

Anyway, in simple terms my question - if I know everything is a string, how can I omit the quotation marks?



i.e. I can do


json.loads('{"mykey":["data0", "data1"]}')

{u'mykey': [u'data0', u'data1']}



But I would like to do
json.loads('{mykey:[data0, data1]}')

Traceback (most recent call last):



The problem is that I don't want to make users have to type redundant characters.

Is it possible?

Thanks,

Steven

Hi,
Thanks to everyone for the responses. I'll look at YAML and ConfigParser.
Steven
 

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,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top