How can I do a UML Schema from a JSON file? - json

Hello I have this JSON file :
{
"Hello": "",
"Olá": [
{
"Hour": "00:04:35",
"hotel": [""],
}
]
"Ciao" : [
{
"Hour": "02:36:52"
}
]
}
And actually I am trying to convert this JSON file to an UML file.
Could you help me please ? :)
I thought of this :
Solution

You may want to take a look at JSONDiscoverer http://som-research.uoc.edu/tools/jsonDiscoverer/#/
(the site includes also the technical details on how the UML model is created)

gliffy diagrams can do it, actually is the original format to save files

Related

Proper validation of a referenced file when editing OpenAPI json in IntelliJ

I'm editing an OpenAPI JSON spec in IntelliJ. The automatic validation and code completion work very nicely.
The OpenAPI version used is 3.0.3, which IntelliJ detects correctly. It seems that it uses "openapi30.json" internally for validation, and all is good.
However, the file is getting very large and it's time to move some commonly-used models out of it using $ref.
This is where things break. The main spec looks like this (snippet):
{
"openapi": "3.0.3",
"info": {
"title": "Cars REST API",
"description": "Calls, Responses and DTOs for REST",
"version": "1.0.0"
},
"components": {
"schemas": {
"car": {
"$ref": "car.json"
},
"car-group": {
"$ref": "car-group.json"
}
And when editing it, IntelliJ recognizes it as "openapi30".
However, the referenced documents are not recognized. For example, the car.json file looks like this:
{
"car": {
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
}
}
And it's recognized simply as a JSON document, not an OpenAPI one, so there is no proper validation and no code completion, etc.
How does one tell IntelliJ that the file is part of an OpenAPI specification, to be validated as such? One should think this could be inferred from begin $ref'ed from the main spec, but this doesn't work.
Trying to add a $schema value in the referenced file had no effect (and probably isn't in line with the OpenAPI spec anyway).
Manually selecting the OpenAPI 3.0 file type for car.json is not helpful, because then validation (rightly) fails - as it doesn't have the top-level structure required (info, openapi, paths).
Perhaps some specific JSON schema mapping needs to be added in IntelliJ preferences? If that's the case, it would be actually a sub-schema or some tag in the main OpenAPI spec, how can that be done?
IntelliJ version is: IntelliJ IDEA 2021.3.2 (Ultimate Edition)
Any help would be greatly appreciated.
Ron!
Such functionality is not yet supported. Please vote for https://youtrack.jetbrains.com/issue/IDEA-284305

Add data to a json file using Talend

I have the following JSON:
[
{
"date": "29/11/2021",
"Name": "jack",
},
{
"date": "30/11/2021",
"Name": "Adam",
},
"date": "27/11/2021",
"Name": "james",
}
]
Using Talend, I wanna add 2 lines to have something like:
[
{
"company": "AMA",
"service": "BI",
"date": "29/11/2021",
"Name": "jack",
},
{
"company": "AMA",
"service": "BI",
"date": "30/11/2021",
"Name": "Adam",
},
"company": "AMA",
"service": "BI",
"date": "27/11/2021",
"Name": "james",
}
]
Currently, I use 3 components (tJSONDocOpen, tFixedFlowInput, tJSONDocOutput) but I can't have the right configuration of components in order to get the job done !
If you are not comfortable with json .
Just do these steps :
In the metaData just create a FileJson like this then paste it in your job as a tFileInputJson
Your job design and mapping would be
In your tFileOutputJson don't forget to change in the name of the data block "Data" with ""
What you need to do there according to the Talend practices is read your JSON. Then extract each object of it, add your properties and finally rebuild your JSON in a file.
An efficient way to do this is using tMap componenent like this.
The first tFileInputJSON will have to specify what properties it has to read from the JSON by setting your 2 objects in the mapping field.
Then the tMap will simply add 2 columns to your main stream, here is an example with hard coded string values. Depending on you needs, this component will also offer you the possibility to assign dynamic data to your 2 new columns, it's a powerful tool for manipulating the structure of a data stream.
You will find more infos about this component in the official documentation : https://help.talend.com/r/en-US/7.3/tmap/tmap; especially the "tMap scenarios" part.
Note
Instead of using the tMap, if you are comfortable with Java, you can use a tjavaRow instead. Using this, you can setup your 2 new columns with whatever java code you want to put as long as you have defined the output schema of the component.
output_row.Name = input_row.Name;
output_row.date = input_row.date;
output_row.company = "AMA";
output_row.service = "BI";

Hard to understand JSONPath containing [?]

In a legacy system I found this JSONPath :
$['data']..['rels'][?]['persons'][*]
I am confused by [?],
as I am trying to rebuild the expected JSON that should by like (but it's not) :
{
"tag1": ["VALUE1"],
"data": [
{
"tag2": "VALUE2",
"rels": [
{
"persons": [
{
"uid": "uid12"
}
],
"tag3": {
"tag4": "tag4"
}
}
]
}
]
}
I used https://jsonpath.com/
Thanks for your help
You're right to be confused by this. It's not valid JSON Path syntax. It's an extension syntax supported by Jayway JsonPath (a JavaScript implementation) that they call "Filter Predicates." You can read about it in the project's readme.
I and a few others have been working on writing an official specification for JSON Path, and I brought this up recently after having seen another question around it. This kind of confusion is something we aim to avoid.

How to remove a block of. code from a json using jq?

I have a json file temp.json like this -
{
"data": {
"stuff": [
.....
]
},
"time": {
"metrics": 83
}
}
I want to remove this particular block of code from the above json file -
,
"time": {
"metrics": 83
}
After removal I want to rewrite new json in the same file so that new content in the same file will be -
{
"data": {
"stuff": [
.....
]
}
}
Is this possible to do by any chance?
Note: number 83 can be any number in general.
Here's an excellent tutorial: Baeldung: Guide to Linux jq Command for JSON Processing.
Maybe you can try something like this: jq 'del(.time)' temp.json > temp2.json.
Note that jq works at the semantic level; it's not just "text substitution". So things like the "comma" separators between objects will be deleted from the JSON text when you use jq to delete the object.
Experiment, and see what works best for your particular scenario.

Monitoring a JSON or YAML config file and showing the parent of the changed attributes

I have a case in which I need to monitor JSON and YAML config files for changes, but all of the solutions that I found only showed line-by-line changes.
For example, if I have a JSON as such:
{
"server-1": {
"name": "A" ,
"metadata":{
"tags": ["X","Y","Z"],
"date-created": "10 March 2021"
}
},
"server-2": {
"name": "B" ,
"metadata":{
"tags": ["W","X","Y"],
"date-created": "11 March 2021"
}
},
}
If server-2's tags were to be changed, I want to get: search-1, metadata, tags as its result.
Does anyone have any ready-to-use solutions that I can use for monitoring purposes?
I am looking for a ready-to-use solutions since the JSON and YAML fields are quite dynamic and contains a lots of fields. I am considering ELK stack or Splunk for this, but I am not quite sure it will work or not.