You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "skyswind@gmail.com" <sk...@gmail.com> on 2013/05/02 10:12:47 UTC

How to get a specific value from a json string?

Hi everyone,

I came across a simple problem and I need some help.

I get a json string from a jms, and I want to get a specific value from the
json string.
how can I do it in blueprint file?

For example, the json from jms queue "FEATURES.JSON" is

 {id:"123",
name:"test",
value:"dfsa"}

I want to get the name and pass it to the queue "RETURN"

how can I achieve it?

 <from uri="jms:queue:FEATURES.JSON" />

some  code here

 <to uri="jms:queue:RETURN"/>

Thank you!

Re: How to get a specific value from a json string?

Posted by "skyswind@gmail.com" <sk...@gmail.com>.
Hi

Thank you for the help!

1.For the json-path library, can you give me some blueprint using example?

2. I have covert the json into a map struction using jackson with the
following code

<route>
<from uri="jms:queue:FEATURES.JSON"/>
<unmarshal>
 <json library="Jackson"/>
</unmarshal>
 <to uri="jms:queue:FEATURES.JSON3"/>
</route>

How can I get the value of "id" field? Can you give me some example?

Thank you again!

黄骞/Huang Qian
超图分布式地理信息研究室主任/ Director of SuperMap Distributed GIS Lab
超图GIS研究所高级研究员/ Senior Researcher at SuperMap GIS Institute
地址:北京市朝阳区酒仙桥北路甲10号电子城IT产业园201楼E门4层,100015
Add: 4/F Unit E, Building 201, No. A10, Jiuxianqiaobei Road, Chaoyang
District, Beijing, 100015, CHINA
电话/Tel:+86-10- 010-59896522
传真/Fax:+86-10-59896666
手机/Mobile:15901268883
电子邮件/Mail: huangqian@supermap.com
网址/Website: http://www.supermap.com.cn


On Thu, May 2, 2013 at 4:25 PM, Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> Yeah I would like to see a json expression language built-in out of
> the box in Camel.
>
> This library seems compelling
> https://code.google.com/p/json-path/
>
> You can also find some talks about json expression libraries here
>
> http://stackoverflow.com/questions/4849816/is-there-a-java-implementation-of-jsonpath
>
> Though you can use the Camel json data format (jackson, gson etc)
> http://camel.apache.org/data-format.html
>
> And turn the data into a Map structure, and then get the value from
> the map afterwards. For that you can use simple, mvel, ognl languages
> to grab the field.
>
> Though I would like that json-path library out of the box as you can
> then do a single expression to grab the field.
> Though it may only work for expressions. Would be nice for predicates
> as well, so you can use it in content based routers / filters etc.
>
>
>
>
>
>
>
> On Thu, May 2, 2013 at 10:12 AM, skyswind@gmail.com <sk...@gmail.com>
> wrote:
> > Hi everyone,
> >
> > I came across a simple problem and I need some help.
> >
> > I get a json string from a jms, and I want to get a specific value from
> the
> > json string.
> > how can I do it in blueprint file?
> >
> > For example, the json from jms queue "FEATURES.JSON" is
> >
> >  {id:"123",
> > name:"test",
> > value:"dfsa"}
> >
> > I want to get the name and pass it to the queue "RETURN"
> >
> > how can I achieve it?
> >
> >  <from uri="jms:queue:FEATURES.JSON" />
> >
> > some  code here
> >
> >  <to uri="jms:queue:RETURN"/>
> >
> > Thank you!
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: cibsen@redhat.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>

Re: How to get a specific value from a json string?

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yeah I would like to see a json expression language built-in out of
the box in Camel.

This library seems compelling
https://code.google.com/p/json-path/

You can also find some talks about json expression libraries here
http://stackoverflow.com/questions/4849816/is-there-a-java-implementation-of-jsonpath

Though you can use the Camel json data format (jackson, gson etc)
http://camel.apache.org/data-format.html

And turn the data into a Map structure, and then get the value from
the map afterwards. For that you can use simple, mvel, ognl languages
to grab the field.

Though I would like that json-path library out of the box as you can
then do a single expression to grab the field.
Though it may only work for expressions. Would be nice for predicates
as well, so you can use it in content based routers / filters etc.







On Thu, May 2, 2013 at 10:12 AM, skyswind@gmail.com <sk...@gmail.com> wrote:
> Hi everyone,
>
> I came across a simple problem and I need some help.
>
> I get a json string from a jms, and I want to get a specific value from the
> json string.
> how can I do it in blueprint file?
>
> For example, the json from jms queue "FEATURES.JSON" is
>
>  {id:"123",
> name:"test",
> value:"dfsa"}
>
> I want to get the name and pass it to the queue "RETURN"
>
> how can I achieve it?
>
>  <from uri="jms:queue:FEATURES.JSON" />
>
> some  code here
>
>  <to uri="jms:queue:RETURN"/>
>
> Thank you!



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen