[Pas2js] JSON proposal

Michael Van Canneyt michael at freepascal.org
Sat Jan 20 14:56:57 CET 2018



On Sat, 20 Jan 2018, warleyalex via Pas2js wrote:

> Please, consider to include in JS unit, the following global external
> variable:
>
> var
>  JSON: TJSJSON; external name 'JSON'; 
>
> and then make sure to remove "class" function for the methods.
>
>  TJSJSON = class external name 'JSON' (TJSObject)
>  Public
>    {class} function parse(aJSON : String) : TJSObject;
>    {class} function stringify(aValue : JSValue) : string;
>    {class} function stringify(aValue,aReplacer : JSValue) : string;
>    {class} function stringify(aValue,aReplacer : JSValue; space: 
> NativeInt) : string;
>    {class} function stringify(aValue,aReplacer : JSValue; space:  String) :
> string;
>  end;
>
> now, we can use everywhere: *JSON.parse( JSObject )*;
>
> instead of the wierd *TJSJSON(JSON.parse( JSObject ))*

That won't happen.

The units give an exact translation of the underlying JS "classes".

Also, the result of parse is not a TJSJSON object, it's a TJSObject, so your
"weird" example is wrong.

There is nothing weird about

var
   A : TJSObject;

begin
   A:=TJSJSON.Parse(SomeString);
end;


Michael.


More information about the Pas2js mailing list