Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #20661

    LifeTimer
    Participant

    I’m trying to implement a JSON-beautifier in an EmEditor macro, but when I attempt to use for example the JSON.parse() method (which is part of the Javascript specification), I only get the following error message:
    ——————————
    ‘JSON’ is undefined
    ——————————
    Does Javascript macros in EmEditor only support a subset of Javascript standard, and in that case which parts?

    Here is a link to the part of the Javascript reference that documents the build-in JSON object:

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON

    #20662

    Stefan
    Participant

    Hi LifeTimer,

    EmEditor utilize the ‘Windows Script Host’, which in turn utilize JScript 5.7 feature set.
     
    Even as WSH says it’s 5.8

    jsV = ScriptEngineMajorVersion() +"."+ ScriptEngineMinorVersion();
    alert(jsV); // 5.8

     –

    See http://stackoverflow.com/questions/5497967/jscript-version-availability-for-wsh-installations

    Note Starting with JScript 5.8, by default,
    the JScript scripting engine supports the language feature set as it existed in version 5.7.
    This is to maintain compatibility with the earlier versions of the engine.

    From MSDN: http://msdn.microsoft.com/en-us/library/s4esdbwz%28v=vs.84%29.aspx

    JScript 5.8 introduced the following features: JSON object, JSON.parse method,
    JSON.stringify method, toJSON method, defineProperty method, getOwnPropertyDescriptor method.

    And further see: http://stackoverflow.com/questions/19445189/cscript-jscript-json
    and perhaps: https://en.wikipedia.org/wiki/Windows_Script_Host
    https://msdn.microsoft.com/en-us/library/s4esdbwz%28v=vs.84%29.aspx

     

    #20696

    Paul
    Participant

    On the MSDN page listed above is this:

    To use the complete language feature set of version 5.8, the Windows Script interface host has to invoke IActiveScriptProperty::SetProperty.

    Is this something on the drawing board? Or is it a setting already in EmEditor and I missed it?

    #20706

    Yutaka Emura
    Keymaster

    Hello,

    On the next beta version (v15.9.0 beat 3), I added the versioning code to set JScript version to 5.8, but unfortunately, it doesn’t seem working. I will still look into the issue.

    #20776

    LifeTimer
    Participant

    Sorry, I missed this reply before (missing forum email notifications again…).

    Did you ever get it working in the 15.9.0 final version?

    If not, there really must be a way to get it working, since it’s such widespread functionality, used by thousands of applications around the world, right?!

    I could absolutely help you to search for clues towards a solution if you just describe the problem a bit further here (i.e. if you didn’t already got it working in the 15.9.0 final version?).

    The following info might be of value:
    http://stackoverflow.com/questions/14811458/how-to-use-jscript-9-features-in-a-vb6-host

    Perhaps especially the following quote?

    The undocumented ‘feature’ of the SetProperty with SCRIPTPTOP_INVOKEVERSIONING is that the value must be a VT_I4 or VT_I2 – any other integer type will be rejected as invalid.

    #20779

    Yutaka Emura
    Keymaster

    EmEditor v15.9.0 supports the JSON object. Here is an example:

    var text = '{ "employees" : [' +
     '{ "firstName":"John" , "lastName":"Doe" },' +
     '{ "firstName":"Anna" , "lastName":"Smith" },' +
     '{ "firstName":"Peter" , "lastName":"Jones" } ]}';
    
    var obj = JSON.parse(text);
    
    alert( obj.employees[1].firstName + " " + obj.employees[1].lastName );
    

    I hope this helps. Thanks for your inputs!

    #20782

    LifeTimer
    Participant

    Thanks a lot for adding this, it works great!

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.