Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Basic JSON question: Do I really need the quotes

68 views
Skip to first unread message

moo...@yahoo.co.uk

unread,
Oct 12, 2012, 10:09:08 AM10/12/12
to
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





Kwpolska

unread,
Oct 12, 2012, 10:14:35 AM10/12/12
to pytho...@python.org
On Fri, Oct 12, 2012 at 4:09 PM, <moo...@yahoo.co.uk> wrote:
> 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.
--
Kwpolska <http://kwpolska.tk>
stop html mail | always bottom-post
www.asciiribbon.org | www.netmeister.org/news/learn2quote.html
GPG KEY: 5EAAEA16

Roel Schroeven

unread,
Oct 12, 2012, 1:27:05 PM10/12/12
to pytho...@python.org
moo...@yahoo.co.uk 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

ro...@roelschroeven.net

Adam Tauno Williams

unread,
Oct 12, 2012, 1:52:42 PM10/12/12
to pytho...@python.org
On Fri, 2012-10-12 at 19:27 +0200, Roel Schroeven wrote:
> moo...@yahoo.co.uk 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
> > Ayway, 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?

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.

Roy Smith

unread,
Oct 12, 2012, 8:03:44 PM10/12/12
to
In article <cbd2f125-38ca-4f46...@googlegroups.com>,
moo...@yahoo.co.uk wrote:

> 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" :-)

rusi

unread,
Oct 12, 2012, 11:30:47 PM10/12/12
to
On Oct 13, 5:03 am, Roy Smith <r...@panix.com> wrote:
> In article <cbd2f125-38ca-4f46...@googlegroups.com>,
>
>  moo...@yahoo.co.uk wrote:
> > 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'

moo...@yahoo.co.uk

unread,
Oct 15, 2012, 1:48:54 AM10/15/12
to
Hi,
Thanks to everyone for the responses. I'll look at YAML and ConfigParser.
Steven
0 new messages