Re: [xwiki-users] Generating pure JSON

2015-04-06 Thread Marius Dumitru Florea
On Sat, Jan 17, 2015 at 10:43 AM, Bryn Jeffries
bryn.jeffr...@sydney.edu.au wrote:
 I'd like to be able to generate pure JSON from a wiki page, to use in other 
 pages via AJAX. To that end I created a page with the following content:
 {{velocity wiki=false}}
 $response.setContentType('application/json')

 {
 greeting : Hello,
 location: World
 }

Instead of printing the JSON directly I recommend using the $jsontool
(see 
http://extensions.xwiki.org/xwiki/bin/view/Extension/Velocity+Module#HVelocityTools
). The advantage is that you don't have to care about escaping JSON
(property) values.

$jsontool.serialize({
  greeting : $someObject.greeting,
  location: $someOtherObject.location
})

Hope this helps,
Marius

 {{/velocity}}

 Calling this via /xwiki/bin/get/Sandbox/JsonTest I get the following code:

 pbr/#123;br/greeting : Hello,br/location: Worldbr/}/p

 I get the same via /xwiki/bin/view/AlertDB/JsonTest?xpage=plain.

 If I remove the $response.setContentType('application/json')
 https://dev.alertnessdb.net/xwiki/bin/view/AlertDB/JsonTest?xpage=plain


 ___
 users mailing list
 users@xwiki.org
 http://lists.xwiki.org/mailman/listinfo/users
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] Generating pure JSON

2015-01-18 Thread vinc...@massol.net
Hi Bryn,

On 19 Jan 2015 at 02:41:00, Bryn Jeffries 
(bryn.jeffr...@sydney.edu.au(mailto:bryn.jeffr...@sydney.edu.au)) wrote:

 Thanks so much for that. It did indeed work :-)
 So 'view' with xpage=plainoutputSyntax=plain or just 'get' with 
 outputSyntax=plain does the job.
  
 Now I know what to look for, for posterity I've put this information into 
 http://extensions.xwiki.org/xwiki/bin/view/Extension/Output+JSON

cool thanks!

 FWIW I'd have rather put the license as something like public domain, but 
 the closest (Do What The F*** You Want..) seemed unnecessarily vulgar. Does 
 such language really have a place on your website?

I agree it looks vulgar. However this is a real license, see 
http://www.wtfpl.net/about/ and http://en.wikipedia.org/wiki/WTFPL

Thanks
-Vincent

 Thanks,
  
 Bryn
  
  
 From: Vincent Massol [vmas...@gmail.com] on behalf of vinc...@massol.net 
 [vinc...@massol.net]
 Sent: 17 January 2015 21:23
 To: XWiki Users
 Cc: Bryn Jeffries
 Subject: Re: [xwiki-users] Generating pure JSON
  
 Hi Bryn,  
  
 On 17 Jan 2015 at 09:43:30, Bryn Jeffries 
 (bryn.jeffr...@sydney.edu.au(mailto:bryn.jeffr...@sydney.edu.au)) wrote:
  
  I'd like to be able to generate pure JSON from a wiki page, to use in other 
  pages via AJAX. To that end I created a page with the following content:
  {{velocity wiki=false}}
  $response.setContentType('application/json')
  {
  greeting : Hello,
  location: World
  }
  {{/velocity}}
 
  Calling this via /xwiki/bin/get/Sandbox/JsonTest I get the following code:
 
   
  
  
 {
 greeting : Hello,
 location: World
 }
  
  
 
  I get the same via /xwiki/bin/view/AlertDB/JsonTest?xpage=plain.
 
  If I remove the $response.setContentType('application/json')
  https://dev.alertnessdb.net/xwiki/bin/view/AlertDB/JsonTest?xpage=plain  
  
 Inded, I would have imagine also that xpage=plain would have worked but it 
 doesn’t. You have to use outputsyntax.  
  
 For example: 
 http://playground.xwiki.org/xwiki/bin/get/Main/VMA?outputSyntax=plain  
  
 Note: You can go on a page with a livetable and check with Chrome dev tools 
 or Firebug the requests done and you’ll see it uses that.  
  
 Thanks  
 -Vincent
  

___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] Generating pure JSON

2015-01-18 Thread Bryn Jeffries
Thanks so much for that. It did indeed work :-)
So 'view' with xpage=plainoutputSyntax=plain or just 'get' with 
outputSyntax=plain does the job.

Now I know what to look for, for posterity I've put this information into 
http://extensions.xwiki.org/xwiki/bin/view/Extension/Output+JSON

FWIW I'd have rather put the license as something like public domain, but the 
closest (Do What The F*** You Want..) seemed unnecessarily vulgar. Does such 
language really have a place on your website?

Thanks,

Bryn



From: Vincent Massol [vmas...@gmail.com] on behalf of vinc...@massol.net 
[vinc...@massol.net]
Sent: 17 January 2015 21:23
To: XWiki Users
Cc: Bryn Jeffries
Subject: Re: [xwiki-users] Generating pure JSON

Hi Bryn,


On 17 Jan 2015 at 09:43:30, Bryn Jeffries 
(bryn.jeffr...@sydney.edu.au(mailto:bryn.jeffr...@sydney.edu.au)) wrote:

 I'd like to be able to generate pure JSON from a wiki page, to use in other 
 pages via AJAX. To that end I created a page with the following content:
 {{velocity wiki=false}}
 $response.setContentType('application/json')
 {
 greeting : Hello,
 location: World
 }
 {{/velocity}}

 Calling this via /xwiki/bin/get/Sandbox/JsonTest I get the following code:



{
greeting : Hello,
location: World
}


 I get the same via /xwiki/bin/view/AlertDB/JsonTest?xpage=plain.

 If I remove the $response.setContentType('application/json')
 https://dev.alertnessdb.net/xwiki/bin/view/AlertDB/JsonTest?xpage=plain

Inded, I would have imagine also that xpage=plain would have worked but it 
doesn’t. You have to use outputsyntax.

For example: 
http://playground.xwiki.org/xwiki/bin/get/Main/VMA?outputSyntax=plain

Note: You can go on a page with a livetable and check with Chrome dev tools or 
Firebug the requests done and you’ll see it uses that.

Thanks
-Vincent

___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] Generating pure JSON

2015-01-17 Thread vinc...@massol.net
Hi Bryn, 


On 17 Jan 2015 at 09:43:30, Bryn Jeffries 
(bryn.jeffr...@sydney.edu.au(mailto:bryn.jeffr...@sydney.edu.au)) wrote:

 I'd like to be able to generate pure JSON from a wiki page, to use in other 
 pages via AJAX. To that end I created a page with the following content:
 {{velocity wiki=false}}
 $response.setContentType('application/json')
 {
 greeting : Hello,
 location: World
 }
 {{/velocity}}
  
 Calling this via /xwiki/bin/get/Sandbox/JsonTest I get the following code:
  


{
greeting : Hello,
location: World
}


  
 I get the same via /xwiki/bin/view/AlertDB/JsonTest?xpage=plain.
  
 If I remove the $response.setContentType('application/json')
 https://dev.alertnessdb.net/xwiki/bin/view/AlertDB/JsonTest?xpage=plain

Inded, I would have imagine also that xpage=plain would have worked but it 
doesn’t. You have to use outputsyntax.

For example: 
http://playground.xwiki.org/xwiki/bin/get/Main/VMA?outputSyntax=plain

Note: You can go on a page with a livetable and check with Chrome dev tools or 
Firebug the requests done and you’ll see it uses that.

Thanks
-Vincent

___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users