Javascript in place of json input step - json

I am loading data from a mongodb collection to a mysql table through Kettle transformation.
First I extract them using MongodbInput and then I use json input step.
But since json input step has very low performance, I wanted to replace it with a
javacript script.
I am a beginner in Javascript and even though i tried somethings, the kettle javascript script is not recognizing any keywords.
can anyone give me sample code to convert Json data to different columns using javascript?

To solve your problem you need to see three aspects:
Reading from MongoDB
Reading from JSON
Reading from (probably) String
Reading from MongoDB Except if you changed the interface, MongoDB returns not JSON but BSON files (~binary JSON). You need to see the MongoDB documentation about reading and writing BSON: probably something like BSON.to() and BSON.from() but I don't know it by heart.
Reading from JSON Once you have your BSON in JSON format, you can read it using JSON.stringify() which returns a String.
Reading from (probably) String If you want to use the capabilities of JSON (why else would you use JSON?), you also want to use JSON.parse() which returns a JSON object.
My experience is that to send a JSON object from one step to the other, using a String is not a bad idea, i.e. at the end of a JavaScript step, you write your JSON object to a String and at the beginning of the next JavaScript step (can be further down the stream) you parse it back to JSON to work with it.
I hope this answers your question.
PS: writing JavaScript steps requires you to learn JavaScript. You don't have to be a master, but the basics are required. There is no way around it.

you could use the json input step to get the values of this json and put in common rows

Related

Extract fields from JSON API response made with Blueprism

I am using Blueprism to make an API Call. The response is a block of json. I need to extract the conversationId from:
{"results":[{"group":{"queueId":"aad701ad-56db-452e-8b70-aa9abd6046c7","mediaType":"email"},"data":[{"metric":"oWaiting","stats":{"count":1},"truncated":false,"observations":[{"observationDate":"2022-01-20T11:19:04.882Z","conversationId":"116b9f91-bf82-4275-9cdc-c405068b4cba","sessionId":"f97de11e-eb99-4781-ae13-33a9e5b6c3f0","routingPriority":0,"direction":"inbound","addressFrom":"e.mc#gmail.ie","addressTo":"info#gmail.ie","requestedRoutings":["Standard"]}]}]}]}
I am using this regex:
^.*? with conversationId ([a-f0-9]+)
but it is not working. Is this the best approach? Is there a better way to do this?
.*conversationId":"([^"]+)".*
will save the conversationId into capture group 1.
If you are using perl, you could do this:
s/.*conversationId":"([^"]+)".*/\1/
this works for your example but it's probably not going to scale well to different input JSON messages. As others have mentioned, the right way to do this is to parse the string into a native JSON object and then extract the field using it's methods.
Ultimately I was going about this the wrong way. I should have been parsing the json and not trying to extract a particular string.
Blueprism has a json object which completes this very function.
https://digitalexchange.blueprism.com/dx/entry/3439/solution/utility---json

How can I query JSON of an XML parsing in a client only app?

Sorry for the inappropriate question. But what do you recommend me to use to structure a library that can put a query arrangement on json formats generated by an XML parsing based on TEI p5? I tried to use GraphQL by converting the interfaces of my Angular application related to parsing information from XML to JSON in type to define a GraphQL schema but I don't think that's the way.
What I have to do is query, client only, some data encoded in XML (also wanting already parsed in JSON) and, for example, search for all occurrences of a specific data.
Do you have any roadmaps to recommend or some JSON query system that might be right for me?
You might take a look at https://www.npmjs.com/package/saxon-js. With SaxonJS you're able to run XPath expression against XML using JavaScript.

Apache Spark Read One Complex JSON File Per Record RDD or DF

I have an HDFS directory full of the following JSON file format:
https://www.hl7.org/fhir/bundle-transaction.json.html
What I am hoping to do is find an approach to flatten each individual file to become one df record or rdd tuple. I have tried everything I could think of using read.json(), wholeTextFiles(), etc.
If anyone has any best practices advice or pointers, it would be sincerely appreciated.
Load via wholeTextFiles something like this:
sc.wholeTextFiles(...) //RDD[(FileName, JSON)
.map(...processJSON...) //RDD[JsonObject]
Then, you can simply call the .toDF method so that it will infer from your JsonObject.
As far as the processJSON method, you could just use something like the Play json parser
mapPartitions is used when having to deal with data that is structured in a way that different elements can be on different lines. I've worked with both JSON and XML using mapPartitions.
mapPartitions works on an entire block of data at a time, as opposed to a single element. While you should be able to use the DataFrameReader API with JSON, mapPartitions can definitely do as you'd like. I don't have the exact code to flatten a JSON file, but I'm sure you can figure it out. Just remember the output must be an iterable type.

VBJSON for VB6 how to serialize object returned from Parse routine

So there is a nice library for VB6 JSON parsing. HERE
but i actually used one that built on the original and optimized. HERE
Essentially I'm using the parser to deserialize the json i get from a web service. I need to update some values, and resend to the server. Using the Collection/Dictionary objects made it very easy. But now, How do i take those objects and serialize them to a JSON string? is there a library for that?
thanks you for your help.
There are quite a few JSON parser/serializer/DOM classes written in VB6. Perhaps you might want to consider one of those instead. E.g.:
JsonBag, Another JSON Parser/Generator

Parsing JSON in VBA, without any external library

I'm really at my wit's end here... I'm using VB-JSON Parser (http://www.ediy.co.nz/vbjson-json-parser-library-in-vb6-xidc55680.html) and I have the following array :
[{"timestamp":1410001952,"tid":2834225,"price":"483.77"}]
The documentation is really minimal and I have no clue whatsoever of how to access the array, been searching for several hours now on how to resolve this.
How can I get the "price" value? I know that i can use .item("price") when there is no array but I don't know what to do when there's an array and there is no name before it.
First have a look at Parsing JSON in Excel VBA
It explains the JScript way of parsing JSON string.
Browsing through the net, I found it really hard to get a complete VBA based JSON parser.
Some options are available in the VB version and then there are few online parsers who promise to parse JSON and convert them in Excel. These ones work fine with simple JSON data structure. But once you feed in a complex data set with nested arrays and structures, they simply fail.
Using JavaScript features of parsing JSON, on top of ScriptControl, we can create a parser in VBA which will list each and every data point inside the JSON. No matter how nested or complex the data structure is, as long as we provide a valid JSON, this parser will return a complete tree structure.
JavaScript’s Eval, getKeys and getProperty methods provide building blocks for validating and reading JSON.
Coupled with a recursive function in VBA we can iterate through all the keys (up to nth level) in a JSON string. Then using a Tree control (used in this article) or a dictionary or even on a simple worksheet, we can arrange the JSON data as required.
Here, you can find a complete VBA example.
There is a JSON serializer in .NET: http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json