You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by salemi <sa...@avaya.com> on 2014/11/13 00:27:03 UTC

camel xmljson add @ signs to the json output. how to remove the @ signs

Hi,

I am using the xmljson to convert xml to json. When I do that then I see @
signs added to attributes of an element see example below. How can I remove
the @ signs from the output.

xml file:
 <?xml version="1.0" encoding="utf-8"?>
<current>
  <city id="5095626" name="Bernardsville">
    <coord lon="-74.57" lat="40.68"/>
    <country>US</country>
    <sun rise="2014-11-12T11:42:13" set="2014-11-12T21:42:48"/>
  </city>
  <temperature value="286.59" min="284.95" max="288.15" unit="kelvin"/>
  <humidity value="68" unit="%"/>
  <pressure value="1006.973" unit="hPa"/>
  <wind>
    <speed value="2.66" name="Light breeze"/>
    <direction value="326" code="NW" name="Northwest"/>
  </wind>
  <clouds value="0" name="clear sky"/>
  <visibility/>
  <precipitation mode="no"/>
  <weather number="800" value="Sky is Clear" icon="01n"/>
  <lastupdate value="2014-11-12T23:06:51"/>
</current>

JSON output:
{
    "city": {
        "@id": "5095626",
        "@name": "Bernardsville",
        "coord": {
            "@lon": "-74.57",
            "@lat": "40.68"
        },
        "country": "US",
        "sun": {
            "@rise": "2014-11-12T11:42:13",
            "@set": "2014-11-12T21:42:48"
        }
    },
    "temperature": {
        "@value": "286.59",
        "@min": "284.95",
        "@max": "288.15",
        "@unit": "kelvin"
    },
    "humidity": {
        "@value": "68",
        "@unit": "%"
    },
    "pressure": {
        "@value": "1006.973",
        "@unit": "hPa"
    },
    "wind": {
        "speed": {
            "@value": "2.66",
            "@name": "Light breeze"
        },
        "direction": {
            "@value": "326",
            "@code": "NW",
            "@name": "Northwest"
        }
    },
    "clouds": {
        "@value": "0",
        "@name": "clear sky"
    },
    "visibility": [],
    "precipitation": {
        "@mode": "no"
    },
    "weather": {
        "@number": "800",
        "@value": "Sky is Clear",
        "@icon": "01n"
    },
    "lastupdate": {
        "@value": "2014-11-12T23:06:51"
    }
}




-----
Alireza Salemi
--
View this message in context: http://camel.465427.n5.nabble.com/camel-xmljson-add-signs-to-the-json-output-how-to-remove-the-signs-tp5759013.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel xmljson add @ signs to the json output. how to remove the @ signs

Posted by Raul Kripalani <ra...@evosent.com>.
Hey guys,

It's me who developed this component, but in Camel we can only go as far as
the Jsonlib library goes. Jsonlib prefixes XML attributes with '@' when
converting them into JSON properties [1]. I think this is correct: without
some kind of differentiation, you wouldn't be able to cycle back from JSON
to XML accurately.

As Claus said, we could add a feature in our camel-xmljson data format to
remove the @ signs, but that would be post-processing and not very
performant.

Please feel free to submit a pull request + JIRA if you'd like this
functionality. The issue tracker is [2]. Make sure to select
'camel-xmljson' as the Component when you file the ticket.

[1]
http://json-lib.sourceforge.net/xref/net/sf/json/xml/XMLSerializer.html#1081
[2] https://issues.apache.org/jira/browse/CAMEL

Regards,

*Raúl Kripalani*
Apache Camel PMC Member & Committer | Enterprise Architect, Open Source
Integration specialist
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk

On Tue, Jan 13, 2015 at 9:01 PM, Vinny <xa...@gmail.com> wrote:

> Do the component developers follow this list? I'd love to see a switch as
> well. Issue tracker for components ?
>
> On Wed Nov 26 2014 at 1:44:01 AM Claus Ibsen <cl...@gmail.com>
> wrote:
>
> > Hi
> >
> > Did you get in contact with the xmjson team about the issue and if
> > they are willing to add a flag to turn this on/off etc?
> >
> > On Tue, Nov 18, 2014 at 9:18 AM, Claus Ibsen <cl...@gmail.com>
> > wrote:
> > > Hi
> > >
> > > Ah great to know it was hardcoded. I would suggest to ask them to add
> > > an option so you can turn that off. As there are use cases where you
> > > only need a one way transformation.
> > >
> > > They could also consider different strategies how to control this
> > > mapping. So there is a default strategy that does as today. And then
> > > people can switch to different ones, such as one that simply dont
> > > include those signs. And another that allow end users to provide their
> > > own mapping code to have 100% control how they want to do that.
> > >
> > > An alternative is that we introduce an option in the Camel component
> > > but then it would need to process the output message and remove those
> > > @ signs. But its IMHO better to improve this in the xmljson library
> > > itself.
> > >
> > > On Mon, Nov 17, 2014 at 9:10 PM, salemi <sa...@avaya.com> wrote:
> > >> Hi Clause,
> > >>
> > >> I looked at their json-lib code and based on what I read they need to
> > have
> > >> the @ sign for the attributes and # for the text elements.
> > >> They need those "annotations" to be able to covert a json properly
> back
> > to
> > >> xml. The @ and # signs are hard coded in their code.
> > >>
> > >> Do you think I should asked to change the code?
> > >>
> > >> Ali
> > >>
> > >>
> > >>
> > >>
> > >>
> > >> -----
> > >> Alireza Salemi
> > >> --
> > >> View this message in context: http://camel.465427.n5.nabble.
> > com/camel-xmljson-add-signs-to-the-json-output-how-to-remove-the-signs-
> > tp5759013p5759220.html
> > >> Sent from the Camel - Users mailing list archive at Nabble.com.
> > >
> > >
> > >
> > > --
> > > Claus Ibsen
> > > -----------------
> > > Red Hat, Inc.
> > > Email: cibsen@redhat.com
> > > Twitter: davsclaus
> > > Blog: http://davsclaus.com
> > > Author of Camel in Action: http://www.manning.com/ibsen
> > > hawtio: http://hawt.io/
> > > fabric8: http://fabric8.io/
> >
> >
> >
> > --
> > Claus Ibsen
> > -----------------
> > Red Hat, Inc.
> > Email: cibsen@redhat.com
> > Twitter: davsclaus
> > Blog: http://davsclaus.com
> > Author of Camel in Action: http://www.manning.com/ibsen
> > hawtio: http://hawt.io/
> > fabric8 <http://hawt.io/fabric8>: http://fabric8.io/
> >
>

Re: camel xmljson add @ signs to the json output. how to remove the @ signs

Posted by Vinny <xa...@gmail.com>.
Do the component developers follow this list? I'd love to see a switch as
well. Issue tracker for components ?

On Wed Nov 26 2014 at 1:44:01 AM Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> Did you get in contact with the xmjson team about the issue and if
> they are willing to add a flag to turn this on/off etc?
>
> On Tue, Nov 18, 2014 at 9:18 AM, Claus Ibsen <cl...@gmail.com>
> wrote:
> > Hi
> >
> > Ah great to know it was hardcoded. I would suggest to ask them to add
> > an option so you can turn that off. As there are use cases where you
> > only need a one way transformation.
> >
> > They could also consider different strategies how to control this
> > mapping. So there is a default strategy that does as today. And then
> > people can switch to different ones, such as one that simply dont
> > include those signs. And another that allow end users to provide their
> > own mapping code to have 100% control how they want to do that.
> >
> > An alternative is that we introduce an option in the Camel component
> > but then it would need to process the output message and remove those
> > @ signs. But its IMHO better to improve this in the xmljson library
> > itself.
> >
> > On Mon, Nov 17, 2014 at 9:10 PM, salemi <sa...@avaya.com> wrote:
> >> Hi Clause,
> >>
> >> I looked at their json-lib code and based on what I read they need to
> have
> >> the @ sign for the attributes and # for the text elements.
> >> They need those "annotations" to be able to covert a json properly back
> to
> >> xml. The @ and # signs are hard coded in their code.
> >>
> >> Do you think I should asked to change the code?
> >>
> >> Ali
> >>
> >>
> >>
> >>
> >>
> >> -----
> >> Alireza Salemi
> >> --
> >> View this message in context: http://camel.465427.n5.nabble.
> com/camel-xmljson-add-signs-to-the-json-output-how-to-remove-the-signs-
> tp5759013p5759220.html
> >> Sent from the Camel - Users mailing list archive at Nabble.com.
> >
> >
> >
> > --
> > Claus Ibsen
> > -----------------
> > Red Hat, Inc.
> > Email: cibsen@redhat.com
> > Twitter: davsclaus
> > Blog: http://davsclaus.com
> > Author of Camel in Action: http://www.manning.com/ibsen
> > hawtio: http://hawt.io/
> > fabric8: http://fabric8.io/
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8 <http://hawt.io/fabric8>: http://fabric8.io/
>

Re: camel xmljson add @ signs to the json output. how to remove the @ signs

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

Did you get in contact with the xmjson team about the issue and if
they are willing to add a flag to turn this on/off etc?

On Tue, Nov 18, 2014 at 9:18 AM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> Ah great to know it was hardcoded. I would suggest to ask them to add
> an option so you can turn that off. As there are use cases where you
> only need a one way transformation.
>
> They could also consider different strategies how to control this
> mapping. So there is a default strategy that does as today. And then
> people can switch to different ones, such as one that simply dont
> include those signs. And another that allow end users to provide their
> own mapping code to have 100% control how they want to do that.
>
> An alternative is that we introduce an option in the Camel component
> but then it would need to process the output message and remove those
> @ signs. But its IMHO better to improve this in the xmljson library
> itself.
>
> On Mon, Nov 17, 2014 at 9:10 PM, salemi <sa...@avaya.com> wrote:
>> Hi Clause,
>>
>> I looked at their json-lib code and based on what I read they need to have
>> the @ sign for the attributes and # for the text elements.
>> They need those "annotations" to be able to covert a json properly back to
>> xml. The @ and # signs are hard coded in their code.
>>
>> Do you think I should asked to change the code?
>>
>> Ali
>>
>>
>>
>>
>>
>> -----
>> Alireza Salemi
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/camel-xmljson-add-signs-to-the-json-output-how-to-remove-the-signs-tp5759013p5759220.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: camel xmljson add @ signs to the json output. how to remove the @ signs

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

Ah great to know it was hardcoded. I would suggest to ask them to add
an option so you can turn that off. As there are use cases where you
only need a one way transformation.

They could also consider different strategies how to control this
mapping. So there is a default strategy that does as today. And then
people can switch to different ones, such as one that simply dont
include those signs. And another that allow end users to provide their
own mapping code to have 100% control how they want to do that.

An alternative is that we introduce an option in the Camel component
but then it would need to process the output message and remove those
@ signs. But its IMHO better to improve this in the xmljson library
itself.

On Mon, Nov 17, 2014 at 9:10 PM, salemi <sa...@avaya.com> wrote:
> Hi Clause,
>
> I looked at their json-lib code and based on what I read they need to have
> the @ sign for the attributes and # for the text elements.
> They need those "annotations" to be able to covert a json properly back to
> xml. The @ and # signs are hard coded in their code.
>
> Do you think I should asked to change the code?
>
> Ali
>
>
>
>
>
> -----
> Alireza Salemi
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-xmljson-add-signs-to-the-json-output-how-to-remove-the-signs-tp5759013p5759220.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: camel xmljson add @ signs to the json output. how to remove the @ signs

Posted by salemi <sa...@avaya.com>.
Hi Clause,

I looked at their json-lib code and based on what I read they need to have
the @ sign for the attributes and # for the text elements.
They need those "annotations" to be able to covert a json properly back to
xml. The @ and # signs are hard coded in their code.

Do you think I should asked to change the code?

Ali





-----
Alireza Salemi
--
View this message in context: http://camel.465427.n5.nabble.com/camel-xmljson-add-signs-to-the-json-output-how-to-remove-the-signs-tp5759013p5759220.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel xmljson add @ signs to the json output. how to remove the @ signs

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

See
http://camel.apache.org/source.html

Though if you are familiar with github you can also find it there.
Which IMHO is much easier

https://github.com/apache/camel

And the component is here
https://github.com/apache/camel/tree/master/components/camel-xmljson

On Fri, Nov 14, 2014 at 6:12 PM, salemi <sa...@avaya.com> wrote:
> where can I find the source code for this?
>
>
>
> -----
> Alireza Salemi
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-xmljson-add-signs-to-the-json-output-how-to-remove-the-signs-tp5759013p5759147.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: camel xmljson add @ signs to the json output. how to remove the @ signs

Posted by salemi <sa...@avaya.com>.
where can I find the source code for this?



-----
Alireza Salemi
--
View this message in context: http://camel.465427.n5.nabble.com/camel-xmljson-add-signs-to-the-json-output-how-to-remove-the-signs-tp5759013p5759147.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel xmljson add @ signs to the json output. how to remove the @ signs

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

No sorry I dont know how to remove those. You are welcome to dive into
the source code and see if there is something we can add. Sounds like
we should add some option to remove the @.

I wonder if they are there so the component can reverse from json, and
then know that if its a @foo then that is an attribute. And thus why
they are included.



On Thu, Nov 13, 2014 at 5:46 PM, salemi <sa...@avaya.com> wrote:
> Hi Claus,
>
> I am using Camel version 2.14.0.
>
> As far as xmljson goes I have used the follwoing parameter tor turn that off
> without a luck
> <xmljson id="xmljson" removeNamespacePrefixes="true" skipNamespaces="true"
> trimSpaces="true"/>
>
> Do you know how turn off the @ sign for xml attributes?
>
> Thanks,
> Ali
>
>
>
>
> -----
> Alireza Salemi
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-xmljson-add-signs-to-the-json-output-how-to-remove-the-signs-tp5759013p5759063.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: camel xmljson add @ signs to the json output. how to remove the @ signs

Posted by salemi <sa...@avaya.com>.
Hi Claus,

I am using Camel version 2.14.0.

As far as xmljson goes I have used the follwoing parameter tor turn that off
without a luck
<xmljson id="xmljson" removeNamespacePrefixes="true" skipNamespaces="true"
trimSpaces="true"/>   

Do you know how turn off the @ sign for xml attributes?

Thanks,
Ali




-----
Alireza Salemi
--
View this message in context: http://camel.465427.n5.nabble.com/camel-xmljson-add-signs-to-the-json-output-how-to-remove-the-signs-tp5759013p5759063.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel xmljson add @ signs to the json output. how to remove the @ signs

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

What version of Camel do you use? And have you configured the xmljson
data format in any way?

The @ is because the xml value is from an xml attribute. I wonder if
there is a way to turn that off in the xmljson library as yeah that is
not needed in the json output.


On Thu, Nov 13, 2014 at 12:27 AM, salemi <sa...@avaya.com> wrote:
> Hi,
>
> I am using the xmljson to convert xml to json. When I do that then I see @
> signs added to attributes of an element see example below. How can I remove
> the @ signs from the output.
>
> xml file:
>  <?xml version="1.0" encoding="utf-8"?>
> <current>
>   <city id="5095626" name="Bernardsville">
>     <coord lon="-74.57" lat="40.68"/>
>     <country>US</country>
>     <sun rise="2014-11-12T11:42:13" set="2014-11-12T21:42:48"/>
>   </city>
>   <temperature value="286.59" min="284.95" max="288.15" unit="kelvin"/>
>   <humidity value="68" unit="%"/>
>   <pressure value="1006.973" unit="hPa"/>
>   <wind>
>     <speed value="2.66" name="Light breeze"/>
>     <direction value="326" code="NW" name="Northwest"/>
>   </wind>
>   <clouds value="0" name="clear sky"/>
>   <visibility/>
>   <precipitation mode="no"/>
>   <weather number="800" value="Sky is Clear" icon="01n"/>
>   <lastupdate value="2014-11-12T23:06:51"/>
> </current>
>
> JSON output:
> {
>     "city": {
>         "@id": "5095626",
>         "@name": "Bernardsville",
>         "coord": {
>             "@lon": "-74.57",
>             "@lat": "40.68"
>         },
>         "country": "US",
>         "sun": {
>             "@rise": "2014-11-12T11:42:13",
>             "@set": "2014-11-12T21:42:48"
>         }
>     },
>     "temperature": {
>         "@value": "286.59",
>         "@min": "284.95",
>         "@max": "288.15",
>         "@unit": "kelvin"
>     },
>     "humidity": {
>         "@value": "68",
>         "@unit": "%"
>     },
>     "pressure": {
>         "@value": "1006.973",
>         "@unit": "hPa"
>     },
>     "wind": {
>         "speed": {
>             "@value": "2.66",
>             "@name": "Light breeze"
>         },
>         "direction": {
>             "@value": "326",
>             "@code": "NW",
>             "@name": "Northwest"
>         }
>     },
>     "clouds": {
>         "@value": "0",
>         "@name": "clear sky"
>     },
>     "visibility": [],
>     "precipitation": {
>         "@mode": "no"
>     },
>     "weather": {
>         "@number": "800",
>         "@value": "Sky is Clear",
>         "@icon": "01n"
>     },
>     "lastupdate": {
>         "@value": "2014-11-12T23:06:51"
>     }
> }
>
>
>
>
> -----
> Alireza Salemi
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-xmljson-add-signs-to-the-json-output-how-to-remove-the-signs-tp5759013.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/