How to convert binary protobuf file to json file in Scala? - json

In my project I have proto file, the respective class files also. I have probuf binary data as blob file format. How can I convert this file to json file? I am very new to Scala.
I came across https://scalapb.github.io/docs/ site. It is not very clear to me. I do not want to install this whole but rather just make use of Json4s to convert protobuf data to json data.
Any pointers? Which library can I use and how can I use it?

The .proto files are your source of truth. There should be no "respective class files"
ScalaPB should be used as an SBT plugin. It will generate "managed" code when you compile your project. That managed code will consist of case classes that mirror the definitions in the proto files and companion objects that can serialize the protobufs.
Managed code is code you do not edit as a user. You won't even see it unless you look for it in the target directory. If your proto files change, the compiler will re-create the proper code to reflect those changes. That is why you should not hand-create these case class files.
Then apply their Json4s helper-lib which cuts down on a few steps

Related

Modify Mxnet nodes in a json file in C++

I have a generic Mxnet model saved into a json file that I load in a C++ script. But depending on the specific case, I need to modify the attributes of many nodes.
Is there a way to do so after (or before) calling LoadJson on that json file?
Thank you.

Best data processing software to parse CSV file and make API call per row

I'm looking for ideas for an Open Source ETL or Data Processing software that can monitor a folder for CSV files, then open and parse the CSV.
For each CSV row the software will transform the CSV into a JSON format and make an API call to start a Camunda BPM process, passing the cell data as variables into the process.
Looking for ideas,
Thanks
You can use a Java WatchService or Spring FileSystemWatcher as discussed here with examples:
How to monitor folder/directory in spring?
referencing also:
https://www.baeldung.com/java-nio2-watchservice
Once you have picked up the CSV you can use my example here as inspiration or extend it: https://github.com/rob2universe/csv-process-starter specifically
https://github.com/rob2universe/csv-process-starter/blob/main/src/main/java/com/camunda/example/service/CsvConverter.java#L48
The example starts a configurable process for every row in the CSV and includes the content of the row as a JSON process data.
I wanted to limit the dependencies of this example. The CSV parsing logic applied is very simple. Commas in the file may break the example, special characters may not be handled correctly. A more robust implementation could replace the simple Java String .split(",") with an existing CSV parser library such as Open CSV
The file watcher would actually be a nice extension to the example. I may add it when I get around to it, but would also accept a pull request in case you fork my project.

How can I use any json or array or any js file in .testcaferc.json?

I have created one file .testcaferc.json that contains all configuration information like browser name, specs, timeouts etc. I want to fetch the configuration data from file so that I have to change the information at only one place
I want to store all these information in single file, I tried, js, json and array. But I can not import all above format files in my .testcaferc.json, when I press Alt+F8 I see the error "Expected a JSON object, array or literal"
Is there any way I can import json, array or js data in .testcaferc.json?
Thanks in advance!!
The JSON format doesn't support any import directives. The TestCafe configuration file (.testcaferc.json) is a simple JSON file. So, the TestCafe configuration file doesn't support such functionality.
To achieve your goal, you can transform the existing .testcaferc.json file before test running: load data from various sources and add/replace values for the appropriate data fields.
Also, there is a suggestion in the TestCafe GitHub repository, which will make your scenario easier to implement. Track it to be notified about its progress.

How can we read a json file only once for entire feature file in karate

I am calling multiple json and js files in my feature file in background, which is required for every scenarion in my feature file.
def test= read('classpath:testData/responseFiles/test.json')
problem is that, it is running/reading for each scenario. Is there something i can do, so that it read only once for feature file and can use for all scenarios. I am using 9.0.0 karate version
callonce is only working to call feature filen not json file
Read the JSON file in a called feature and then use callonce.

Convert Json file into GraphJSON to be imported into Titan

I have been looking at ways to convert a JSON file into a GraphJSON graph and I have come across the GraphJSON Reader and Writer Library.
However, what I do not really understand is whether I can read out directly from a path where a JSON file resides and parse it into a graph/GraphJSON.
Can you help?
This is how I would solve this issue:
Read your JSON files using GSON or Jackson, then
Feed this data into a subclass of Vertex/Edge of your implementation of these Tinkerpop 3 interfaces.
Use the GraphSON writer methods to "graphitise" your data, save your data into an OutputStream.
I'm assuming you're using Tinkerpop3 and Titan 1.0.0, this is the right documentation.
Good luck!
P.S: If you're doing this for the sack of importing data into Titan, you might be overcomplicating the issue of data import. Just import it straight away.