• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is This Valid JSON?

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having to query a SOLR server and it can return json which would be great expect I think the json is somewhat invalid. Here is a sample:



The reason I think it is invalid is because there are really 2 root elements; responseHeader and response. They are on the same level and they have no parent. So getting a JSON to Java Serializer to work with this is proving difficult. Any thoughts/opinions/suggestions?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64617
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's perfectly valid to have as many properties at any level as you like.
[ July 30, 2008: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64617
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Analogous to:


Remember that a Javascript object is much more like a Java Map than it is like a Java Object. (And even Java Objects can have multiple properties, so I'm not sure where the XML-like single-root concept is coming from.)
[ July 30, 2008: Message edited by: Bear Bibeault ]
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
It's perfectly valid to have as many properties at any level as you like. It does look like there's a syntax issue with quoting though.


Well, the quoting doesn't seem to be causing any problems. At least not with XStream. What I ended up having to do to get XStream to serialize it is I put a prefix and a suffix on the returned json string. So now it looks like this:



I have a SolrResponse class that contains the responseHeader and response properties which are classes themselves.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Analogous to:


Remember that a Javascript object is much more like a Java Map than it is like a Java Object.


Right, and if it was being dumped straight into JavaScript then sure. But I'm really only having to deal with the response in Java code. Thanks though.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64617
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gregg Bolinger:
Well, the quoting doesn't seem to be causing any problems.
That was just my eyes playing trick on me.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64617
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At a quick glance is not XStrema an XML serializer? In that case, I can see the single-root limitation. But a Java serializer should not have any issues with that perfectly valid JSON.
[ July 30, 2008: Message edited by: Bear Bibeault ]
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
At a quick glance is not XStrema an XML serializer? In that case, I can see the single-root limitation. But a Java serializer should not have any issues with that perfectly valid JSON.

[ July 30, 2008: Message edited by: Bear Bibeault ]


Your are right, although XStream can also do JSON now. But I think it goes to XML and then to JSON which seems silly to me. My Java JSON lib of choice is typically FlexJSON but it only goes one way; java to json. What do you use?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64617
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been using StringTree's Java->JSON. Haven't had a need yet to go the other way.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic