JSON-encode() function

Posted by ssouthwe on 20-Oct-2014 14:17

Now and then in WebSpeed, we find it convenient to output the value of ABL variables or fields into JavaScript.  For example:

<script>
var myString = '`customer.name`';
</script>

The problem with the above is that if customer.name contains an apostrophe or backslash, you could have problems with the way that JavaScript will interpret it.  Backslash is a control character

PHP language has a function called JSON-Encode() that will just return the JSON representation of a variable.  I know ABL has some ways to turn temp-tables or datasets into JSON, but is there a simple way to do this with the ABL for a character variable?  

e.g.:

<script>
var myString = `json-encode(customer.name)`;
</script>

I have rolled my own types of functions for this over the years, but just wondered if there was a better way.

All Replies

Posted by Peter Judge on 20-Oct-2014 14:39

In 11.0+ there are built-in classes for working with JSON (like JsonObject and JsonArray), that take care of making stuff JSON-compliant.
 
I do not know whether these classes are available in SpeedScript, though.
 
-- peter
 
[collapse]
From: ssouthwe [mailto:bounce-ssouthwe@community.progress.com]
Sent: Monday, 20 October, 2014 15:18
To: TU.OE.Development@community.progress.com
Subject: [Technical Users - OE Development] JSON-encode() function
 
Thread created by ssouthwe

Now and then in WebSpeed, we find it convenient to output the value of ABL variables or fields into JavaScript.  For example:

<script>
var myString = '`customer.name`';
</script>

The problem with the above is that if customer.name contains an apostrophe or backslash, you could have problems with the way that JavaScript will interpret it.  Backslash is a control character

PHP language has a function called JSON-Encode() that will just return the JSON representation of a variable.  I know ABL has some ways to turn temp-tables or datasets into JSON, but is there a simple way to do this with the ABL for a character variable?  

e.g.:

<script>
var myString = `json-encode(customer.name)`;
</script>

I have rolled my own types of functions for this over the years, but just wondered if there was a better way.

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by jmls on 20-Oct-2014 14:43

yes, they are ;)

On 20 October 2014 20:40, Peter Judge
wrote:
> RE: JSON-encode() function
> Reply by Peter Judge
> In 11.0+ there are built-in classes for working with JSON (like JsonObject
> and JsonArray), that take care of making stuff JSON-compliant.
>
> I do not know whether these classes are available in SpeedScript, though.
>
> -- peter
>
>[collapse] From: ssouthwe [mailto:bounce-ssouthwe@community.progress.com]
> Sent: Monday, 20 October, 2014 15:18
> To: TU.OE.Development@community.progress.com
> Subject: [Technical Users - OE Development] JSON-encode() function
>
> JSON-encode() function
> Thread created by ssouthwe
>
> Now and then in WebSpeed, we find it convenient to output the value of ABL
> variables or fields into JavaScript. For example:
>
>
>
> The problem with the above is that if customer.name contains an apostrophe
> or backslash, you could have problems with the way that JavaScript will
> interpret it. Backslash is a control character
>
> PHP language has a function called JSON-Encode() that will just return the
> JSON representation of a variable. I know ABL has some ways to turn
> temp-tables or datasets into JSON, but is there a simple way to do this with
> the ABL for a character variable?
>
> e.g.:
>
>
>
> I have rolled my own types of functions for this over the years, but just
> wondered if there was a better way.
>
> Stop receiving emails on this subject.
>
> Flag this post as spam/abuse.
>
> Stop receiving emails on this subject.
>
> Flag this post as spam/abuse.



--
Julian Lyndon-Smith
IT Director,
dot.r
http://www.dotr.com[/collapse]

Posted by jmls on 20-Oct-2014 14:45

aarggh. let me rephrase that. They work in standard webspeed ..

This thread is closed