Tagged: javascript, JSON, macros
- AuthorPosts
- March 14, 2016 at 2:21 pm #20661LifeTimerParticipant
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
March 15, 2016 at 3:56 am #20662StefanParticipantHi LifeTimer,
EmEditor utilize the ‘Windows Script Host’, which in turn utilize JScript 5.7 feature set.
Even as WSH says it’s 5.8jsV = 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
—April 8, 2016 at 2:30 pm #20696PaulParticipantOn 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?
April 12, 2016 at 2:43 pm #20706Yutaka EmuraKeymasterHello,
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.
April 20, 2016 at 2:12 pm #20776LifeTimerParticipantSorry, 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-hostPerhaps 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.“
April 20, 2016 at 4:00 pm #20779Yutaka EmuraKeymasterEmEditor 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!
April 21, 2016 at 5:44 am #20782LifeTimerParticipantThanks a lot for adding this, it works great!
- AuthorPosts
- You must be logged in to reply to this topic.