Json


(Clinton Gormley) #1

Hiya

I like the look of ElasticSearch, and am planning on using it on our
website, assuming my testing works out.

I'm writing a Perl wrapper around it, and one issue I've come across
is that the JSON it returns is not strictly correct. According to the
JSON specs (http://www.json.org/), property names should be quoted,
eg:

Correct: { "foo": "bar"}
Incorrect: { foo: "bar"}

The fastest and safest JSON parser available for Perl only accepts
valid JSON, so it'd be great for us to get this corrected.

thanks

Clint


(Shay Banon) #2

Hey,

elasticsearch returns valid JSON in all of its APIs. The only place where
there is no JSON formatting is on the source JSON you used to index. If the
JSON you used to index the data does not have quotes, then it will be
returned without quotes. Maybe thats what you are seeing? If not, then can
you post which API does not have a valid JSON?

p.s. I use a "non valid" JSON in the samples since it makes them more
readable, but elasticsearch will also parse valid JSON of course ;).

-shay.banon

On Sun, Feb 14, 2010 at 8:16 PM, Clinton clinton@iannounce.co.uk wrote:

Hiya

I like the look of ElasticSearch, and am planning on using it on our
website, assuming my testing works out.

I'm writing a Perl wrapper around it, and one issue I've come across
is that the JSON it returns is not strictly correct. According to the
JSON specs (http://www.json.org/), property names should be quoted,
eg:

Correct: { "foo": "bar"}
Incorrect: { foo: "bar"}

The fastest and safest JSON parser available for Perl only accepts
valid JSON, so it'd be great for us to get this corrected.

thanks

Clint


(Clinton Gormley) #3

I'm writing a Perl wrapper around it, and one issue I've come across
is that the JSON it returns is not strictly correct.

Actually, there seems to be a bug in the JSON handling. It seems that
you accept invalid data (eg with unquoted property names), store it as a
string, but then you return that string as though it were valid JSON.

Compare:

  1. VALID JSON IN -> VALID JSON OUT

curl -XPUT http://localhost:9200/twitter/tweet/1 -d '
{
"user" : "kimchy"
}
'


{"ok":true,"_index":"twitter","_type":"tweet","_id":"1"}

> curl -XGET http://localhost:9200/twitter/tweet/1
----------------------------------------------------------
{"_index":"twitter","_type":"tweet","_id":"1", "_source" :
{
"user" : "kimchy"
}
}

2) INVALID JSON IN -> INVALID JSON OUT

curl -XPUT http://localhost:9200/twitter/tweet/2 -d '
{
user : "kimchy"
}
'
----------------------------------------------------------
{"ok":true,"_index":"twitter","_type":"tweet","_id":"2"}

curl -XGET http://localhost:9200/twitter/tweet/2
----------------------------------------------------------
{"_index":"twitter","_type":"tweet","_id":"2", "_source" :
{
user : "kimchy"
}
}

clint

--
Web Announcements Limited is a company registered in England and Wales,
with company number 05608868, with registered address at 10 Arvon Road,
London, N5 1PR.


(Clinton Gormley) #4

elasticsearch returns valid JSON in all of its APIs. The only place
where there is no JSON formatting is on the source JSON you used to
index. If the JSON you used to index the data does not have quotes,
then it will be returned without quotes. Maybe thats what you are
seeing? If not, then can you post which API does not have a valid
JSON?

It seems our posts crossed in the ether :slight_smile:

clint


(Shay Banon) #5

Maybe in the future Google Wave will come to the rescue :).

On Sun, Feb 14, 2010 at 8:44 PM, Clinton Gormley clinton@iannounce.co.ukwrote:

elasticsearch returns valid JSON in all of its APIs. The only place
where there is no JSON formatting is on the source JSON you used to
index. If the JSON you used to index the data does not have quotes,
then it will be returned without quotes. Maybe thats what you are
seeing? If not, then can you post which API does not have a valid
JSON?

It seems our posts crossed in the ether :slight_smile:

clint


(system) #6