Visualize JSON models as domain model - json

Is there a way to display a bunch of JSON objects, WITH relations, as a domain model?
Models could be something like this:
{
"name": "Order",
"status": {
"type": "number",
"null": false,
"default": 1
}
},
"relations": {
"customer": {
"type": "belongsTo",
"model": "Customer",
"foreignKey": "customerId"
}
}
}
Basically, as this image shows, Domain model -to-> code... but the other way around.?
Thanks
PS: If there are no tools that do this out of the box, I assume that there might be frameworks that I could use to create this.. any recommendations?

As I understand your question you are asking if a utility exists that can turn your JSON code into a domain model. If I understand correctly the answer is yes. There is one project on github that is doing something similar: json-discoverer
From the project page you will see the tool was inspired by some research which was published in ICWE (International Conference on Web Engineering) 2013 and 2014. Below is a link to the main article, as it is quite lengthy and detailed I will not attempt to summarize it here.
Discovering Implicit Schemas in JSON Data
Unfortunately, as you mention you can't then edit the domain afterward. But I have still found it to be a fairly useful tool.
I am unaware of any other existing utilities. The only other alternatives are fairly easy to find with a simple search, but only allow for conversion to trees and/or tables.

Related

How do you create custom settings for a vs code extension?

I have been researching for hours but to no avail.
Pretty much all VsCode extensions will have custom made settings, and they show up in the default settings json file like this from the Red Hat Java extension:
"java.dependency.showOutline": true,
I'm trying to write my own extension and I have found a lot of useful stuff, I can create custom themes, snippets, commands, etc. and it's all well documented on the VsCode API site, but I need to create custom user-defined settings, and I cannot find ANYWHERE that explains how to do so. Does anyone know?
This is done using contribution points, JSON declarations in the contributes field of your extension's package.json file.
You want the configuration contribution point.
For example:
// package.json
{
"contributes": {
"configuration": {
"title": "",
"properties": {
"scope.name": {
"type": "",
"default": "",
"description": ""
}
}
}
}
}
Then you can read those values using
vscode.workspace.getConfiguration('your-extension-name')

Should the server respond one json for all content data on the page in SPA or is better to split it?

I'm building API for SinglePageApplication, which handle by Angular in frontend. One thing is not clear to me.
Supose the web applcation has delati journal paige wich display journal,some articles which belongs to this journal and some cool authors which can be not connected to this journal.
Should I build my api urls based on each need page content, for example:
from url /api/journal/<journal_id>
send json:
{
"journal": {
"id": 10,
"name": "new_journal",
"articles": [
{
"name": "cool_article",
"id": 42
},
{
"name": "another_cool_article",
"id": 43
}
]
},
"authors": [
{
"name": "some_name",
"id": 42
},
{
"name": "another_name",
"id": 43
}
]
}
Or I should build my api based on concrete objects and related objects of them.
With urls like this:
/api/journals/<journal_id>
/api/authors/
And frontend side build this page with two GET requests for fetching content.
Sory if my question too broad, I just want to find best bractice for building API to SinglePageApplications.
Does it have any difference of building API enpoints for external web-apps and what I should do if page need to display more objects, which not belong together? Which of the options above is better?
There isn't really a universal right answer for this. It largely depends on the use case for that data you're fetching. I would say to err on the side of splitting this into multiple requests as it grants you flexibility and efficiency in terms of partial updates to the page. That approach also makes exposing an API to the public much easier in terms of being able to just expose what you already have.
If you're dealing with a potentially large (an intentionally relative term) number of concurrent requests though, you may build some composites of related data to mitigate that.
Of course, you could also do a combination of the two as well (first load makes 1 large request, subsequent updates are segmented).

PATCH multiple resources

Short: Is it standard-compliant, RESTful and otherwise good idea to enable PATCH requests to update a collection of resources, not just a single one, but still individually?
Long:
I'm considering exposing a method for enabling batch, atomic updates to my collection of resources. Example:
PATCH /url/myresources
[
{
"op": "add",
"path": "/1", // ID if the individual resource
"value":
{
... full resource representation ...
}
},
{
"op": "remove",
"path": "/2"
},
{
"op": "replace",
"path": "/3/name",
"value": "New name"
}
]
The context is a public API of a commercial solution. The benefits of allowing such PATCHes is the atomicity as well as batch-friendliness without spamming requests, handling failures individually etc.
I've consulted https://www.rfc-editor.org/rfc/rfc6902 and https://www.rfc-editor.org/rfc/rfc5789 but couldn't find a definitive answer if this is compliant. The RFCs mostly refer to "a resource", but a collection of resources could also be treated as such.
Is this a good idea? Are there better alternatives?
I like this idea. A collection is a resource, too. So acting on it is perfectly good REST.
The semantic of your PATCH request would be that every subresource not listed in the request body is to be left as it is. Every subresource that is listed is to be changed as described. Yes, that sounds good to me.
As long as every segment of the request can be executed in a single request, I see no problems. Both your "all in one" request and single requests like this would be fine.
PATCH /url/myresources/1
{
"op": "add",
"value":
{
... full resource representation ...
}
}

Kibana/ElasticSearch dashboard json schema definition

We've been using Kibana/ElasticSearch to analyze our logs for a bit and I'm trying to understand the dashboard definitions a bit. When I export a dashboard and inspect the resulting file, I can see that it's json. As such, I can manipulate it by hand and one thing I've found helpful is to add custom attributes for comments to my filters. e.g.
"2": {
"_filter_comment": "comment justifying this filter",
"type": "field",
"field": "msg",
"query": "\"something I want to filter\"",
"mandate": "mustNot",
"active": true,
"alias": "",
"id": 2
},
This then allows me to see the comment in Kibana. Playing with the json, I've been able to learn some more helpful tips, but I'd prefer to go to the "source" (a.k.a. docs) assuming such a thing exists to expedite my understanding. One specific feature that I'd love to get a better understanding of is how to use regexes in my filters. Does such a "source" exist, and if so can someone direct me to it?
The only documentation that I found is the one that they have in the folder docs in their Github repo. At the moment, I do not think that there is more docs provided by them, as I mention in this question.

Does anyone know of a webservice for looking up definitions of words that would be able to return results in JSON?

I found http://words.bighugelabs.com/api.php but nothing like this for definitions/dictionary.
Ideally I'd grab a dictionary file and build my own API for this, but this is for a demo and we need something short-term that can be called from within a javascript function.
wiktionary.org provides an API for example:
http://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=Television&format=json
gives back
{
"query": {"searchinfo": {"totalhits": 208862},
"search": [{
"ns": 0,
"title": "Television",
"snippet": "<span class='searchmatch'>Television<\/span> (TV) is a widely used telecommunication medium for transmitting and receiving moving images , either monochromatic (\"black <b>...<\/b> ",
"size": 28228,
"wordcount": 3566,
"timestamp": "2009-10-02T15:09:56Z"},
...
]},
"query-continue": {"search": {"sroffset":10}}
}
I think this is what you are looking for
bighugelabs API - Json fromat
aonaware services - XML format
Not sure if it would fit your needs, but answers.com has webmaster tools that offer various services, including dictionary lookup. Don't know if any can be called from javascript.
At short notice you could set up a reverse-proxy on your server that lets you AJAX your favorite dictionary website and then 'scrape' the definitions from the document that is returned. It's obviously not a long term solution but for a one time thing, you probably won't get into trouble.
This is a web service and have several dictionaries:
http://services.aonaware.com/DictService/DictService.asmx
P.S. I did not notice the JSON part of your question.