Mac Office 2011 and json parsing in vba? - json

all the json libraties I could find for VBA required the dictionary object which is part of the microsoft scripting runtime, which are not available on the mac. Is there a json parser working for Mac Office 2011 VBA?

I did this a long time ago and I did not have a reference to the MS Scripting Runtime in the project. I used microsoft JScript and grabbed objects from it to parse the data. I dug out a thread from 2008 where a few people are talking about the same thing:
Yahoo message thread
It at least gives you a starting point. I've since lost that code where I did it myself. If your still stuck later give me a holler, maybe I can help some more

http://code.google.com/p/vba-json has a json parser in pure VBA, and it seems to work fine, although I seem to recall having to make some minor modifications to get it working on all the JSON I was throwing at it. I also implemented a vba-coded Dictionary object to remove the dependency on the Scripting dictionary. You can find the one I used at http://www.sysmod.com/Dictionary.cls. Using both of these, I was able to get it working on OSX Office 2011, e.g.:
dim js
json_string = ...
Set jsp = New json
Set js = jsp.parse(sjson) 'sets js e.g. to a Dictionary or Collection object if json_string is "{...}" or "[...]"
Let me know if you need more detail to get it working.

Related

How can I get Access to Parse (de)Serialized JSON

I have an API that is passing data back to an MS Access Module. The data that's coming back is JSON, but it's in this format:
{
"<Field1>k__BackingField":"SomeValue"
"<Field2>k__BackingField":"SomeOtherValue"
}
I have found a few Parsers available for access that works with the standard JSON format, but nothing that seems to work with this. I'm actually not even sure what this is... I know it has to do with being Serialized, but... beyond that, I'm clueless... perhaps there's some modification to an existing utility like the one below that I should try?:
https://github.com/VBA-tools/VBA-JSON

Json parsing in IBM Worklight

I am trying to achieve something like which is mentioned in this link
but i don't know whereto write the parsing code. I tried to write it in new method and added the method in "my adapter.xml" but nothing happens. I even don't know how to log in IBM WorkLight. I used WL.logger(some) but its throwing error that "Logger can not be called on an object".
Any help would be appreciated. Thanks in advance.!
In most cases you don't need to manually parse responses because WL adapter framework will do this for you. Anything you retrieve via WL.Server.invokeHttp API will be parsed to JSON automatically unless you specify returnedContentType:"plain". In case you DO need to manually parse JSON you can use JSON.parse() and JSON.stringify() APIs.
Server side logging is achieved via WL.Logger.debug/error/info etc. You can get more info about it here
You don't have to parse JSON data, there are libraries in Javascript to do that. Try JSON.parse(). You should learning how to write adapters and invoking them from clients. The Getting Started modules are a good place to start, specifically Module 4 in your case.

How to encode JSON in ABAP before 7.02

As Horst Keller mentioned in his ABAP and JSON post, "with Releases 7.02 and 7.03/7.31 (Kernelpatch 116) JSON is supported natively in ABAP".
Appartently 7.02 in my case of too generic because the line below:
writer = cl_sxml_string_writer=>create( type = if_sxml=>co_xt_json ).
returns the error: "The field CO_XT_JSON is unknown, but there is a field with the similar name CO_XT_XOP".
So is there any way to easily generate JSON?
Edit: Screenshot from SAP - Status
About the class CL_TREX_JSON_SERIALIZER: I also used this class during developping a mobile sap application and I found the created JSON not being valid, thus I started googling and found this http://scn.sap.com/community/mobile/blog/2012/09/24/serialize-abap-data-into-json-format (which also explains how to create a valid JSON serializer).
Validate your json with json lint http://jsonlint.com/ to see if it is valid.. otherwise, thats for sure, you get a lot of trouble in debugging why it doenst work and dont get the point that the serializer is corrupt. regards, zY
take a look at the ZCL_MDP_JSON Library. You can parse/encode any JSON. So, it is best suited for JSON scenarios that requires flexibility.
It is easy to understand if you have used JSON in other languages. You only need to study methods of ZCL_MDP_JSON_NODE class once & look at the examples.
Here is an extended overview of the library:
http://scn.sap.com/community/abap/blog/2016/07/03/an-open-source-abap-json-library--zclmdpjson
GitHub repo with examples directory: https://github.com/fatihpense/zcl_mdp_json
Disclaimer: I'm the author of the project. If you have questions, don't hesitate to contact me.
Here is some code I wrote for ABAP data <-> JSON conversion some time ago before the new capabilities were included with ABAP (or maybe it was just an older system).
https://gist.github.com/mydoghasworms/2291540
Include the code in your ABAP source and use the method data_to_json of the class.
A nice overview of custom ABAP <-> JSON serializers including yet another one can be found in this blog post
Most popular from my point of view is SE38's ZJSON-library which can be installed using SAPLINK (and which - in contrast to many others) has an explicit license attached to it: Apache 2.0
If upgrading to a newer patch isn't an option in the short term, you can also use class CL_TREX_JSON_SERIALIZER to serialise objects to JSON. A little bit of a quick-and-dirty solution but it works well.

What is JSONC? Are JSONC and JSON-C different?

Recently came across the term JSONC in a YouTube API. I browsed the Web, but found nothing much about it. Can someone explain whether these two are the same or different?
There is also jsonc aka "JSON with comments", created by Microsoft and used by Visual Studio Code. The logic for it can be found here, alas without exhaustive specification (though I'd like to be proven wrong on this).
On top of that there is this project with an actual specification which is also called jsonc, but also does far more than just adding comments.
While there definitely is a use for these technologies, some critical thinking is advised. JSON containing comments is not JSON.
JSON-C seems to just be a variation of JSON mainly targeted at C development. I.e., from the open source docs, "JSON-C implements a reference counting object model that allows you to easily construct JSON objects in C, output them as JSON formatted strings and parse JSON formatted strings back into the C representation of JSON objects."ref^1
From the YouTube API perspective (specifically, version 2, not the new version 3), The JSON-C response is just a condensed version of the JSON response (removing "duplicate, irrelevant or easily calculated values").ref^2
Why would the JSON response have "duplicate, irrelevant or easily calculated values" values anyway? Because it is converting the original ATOM XML format directly to JSON in a loseless conversion. You can find out more details here.
However, I would suggest using version 3 of the YouTube Data API. It is much easier to use. =)
JSONC is an open-source, Javascript API created by Tomás Corral Casas for reducing the size of the amount of JSON data that is transported between clients and servers. It uses two different approaches to achieve this, JSONC.compress and JSONC.pack. More information can be found on the JSONC Github page:
https://github.com/tcorral/JSONC

Parsing and Writing JSON using Ant

Has anyone managed to parse and write JSON in a task in Ant?
I need to parse a json file, modify it and then write it back on disk. I managed to parse it using the rhino engine from JDK 6 but i'm stuck because I don't know how to serialize it back to disk.
It seemes I need a JSON serializer, rhino does not apparently include one.
Recent versions of Rhino should have a JSON object: see this bug that was resolved as fixed in 2010, and the actual class is called NativeJSON and has a stringify method that should let you retrieve a JSON string.
JSON.stringify is available with Rhino 1.7R3 onwards as part of the ECMAScript 5 work.
See: https://developer.mozilla.org/En/New_in_Rhino_1.7R3