Create domain classes according to given JSON file - json

I'm new to Grails, and I'm stuck on the basic structure of my web-app
So far I've implemented a Grails app that renders one JSON file to a readable table.
example
Given JSON file below
{
"abbreviation": "EXAMPLE",
"guid": "31ac235e2-3ad3-43e3-1fd4-41e6dfwegf03",
"metadata": {
"dataOrigin": "Example"
},
"rooms":
[
],
"site": {
"guid": "31ac235e2-3ad3-43e3-1fd4-41e6dfwegf03"
"title": "Example Testing"
}
}
My app renders above JSON file to below
Abbreviation : Example
GUID : 31ac235e2-3ad3-43e3-1fd4-41e6dfwegf03
Metadata : - DataOrigin : Example
Rooms : []
Site - GUID : 31ac235e2-3ad3-43e3-1fd4-41e6dfwegf03
Title : Exmaple Testing
Now, what should I do if I want my app to read JSON files with different Name/value pairs and renders it similarly to what my app does now?
(I've hard coded the application I have now)
I know this question is very vague, but can anyone give me any directions or insights on how to do this?

I'm afraid if there was a simply answer to this question then half of the web developers would be out of their jobs :-)
Anyway, there's probably several steps that could help in achieving your goal.
JSONSlurper(http://docs.groovy-lang.org/latest/html/gapi/groovy/json/JsonSlurper.html) to read JSON files. Obviously if you go for predefined structures you could use GSON (https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/Gson.html) or similar library.
To display arbitrary data you can use the Grails Fields plugin(https://grails.org/plugin/fields).
I know it's all only pointers.

Related

How to mark in a json file which schema describes it

My goal is simple: I want to know what schema describes the given json file, meaning I need to mark it somehow. Example:
{
"Id": 100,
"name": "example"
}
What is not clear from the example below is what schema definition describes it, in other words what are the required fields and what are the other fields available in it.
I'm looking not only for validation, but rather ease-of-work with this jsonn file. For example, I'd like to use it as a configuration file. I need to know what properties are available and what properties are mandatory.
I'm looking for something like this:
{
"$schemaDefinition": "URL to the schema definition",
"Id": 100,
"name": "example"
}
What I don't know is what is the valid way doing it. I read through back and forth the json-schema.org but it doesn't discusses this. However, I remember I saw this solution somewhere.
As a result, I hope..., editor can pick up the schema and provide intellisense. Or the poor person who is going to work with the json file (configure something) knows where to look for available and mandatory configuration properties.
I have found it.
{
"$schema": "URL to the schema definition",
"Id": 100,
"name": "example"
}
If the schema file is stored in Github you have to use the url to the raw content.
Jetbrains products can pick up the schema definition without any problem.

Building an Angular app that hosts articles using JSON files?

I am working on an Angular application (using Angular 9) to build out a website that has articles written by my organization. I would be publishing the articles on my own time after reviewing their emailed submissions to me. I am thinking of using JSON files for each article, structured as such:
[
{
"id": 1,
"title": "Test Title",
"author": "Test Author",
"disclaimer": "Test Disclaimer",
"body": "Test Body"
}
]
I am not sure if the id field is necessary but I saw it being used on a lot of JSON/Angular demos online so I thought I would include it as a unique identifier to each JSON file. Does anyone have any resources on how I can take these JSON files to create and format articles for my website? Any links to examples and resources would be helpful. I have been trying to find some but have had no luck. Thank you.
Well it up to you what all things you need to display. Your format looks good.
According to me following things need to maintained
Unique id
Title
author
Article itself
votes(if you are maintaining)
dateCreated
But any other schema will work as it varies application to application

Angular use Json for blog posting vs BBDD

I'm doing an app with angular since it's easy for me to make it work as a progressive web app, etc. In my app I have a blog section.
The problem is that I need to load a json files dynamically because I'm using it to make new post pages as entry blogs.
I need to know if i can create something like a folder named json and throw all my json files with the content of each post, keeping the angular parsing the folder and looking for new jsons while it's in run time. Or i must use a backend with some mongo or mysql bbdd?
You need to use backend to implement.
Try to receive the service response in JSON array as below:
{
"posts": [
{
"author": "Chinua Achebe",
"content": "abc"
},
{
"author": "Hans Christian Andersen",
"content": "def"
}
]
}
Just iterate over the posts array to display your posts

How to I manage state inside a file in Go?

Hard to admit it but I struggle to manage state in my cli go app. What I basically want is to manage a list of objects with their properties in a file on disk. I want to be able to add objects with their properties, update objects and/or their properties and remove them if needed.
I thought it would be easy to just have a yml or json file and edit it with some kind of library but it seems harder than it should for a go beginner like me.
An example would be the following json structure.
{
"servers":
[
{ "hostname": "gandalf", "ip": "192.168.1.10", "color": "red" },
{ "hostname": "bilbo", "ip": "192.168.1.11", "color": "blue" },
{ "hostname": "frodo", "ip": "192.168.1.12", "color": "yellow" }
]
}
Now I want to be able to add, remove and edit servers. It doesn't have to be json, yaml is fine as well.
Do you girls and guys have any suggestions (libs and an example) on how to do it? I already tried Viper but adding new objects or even editing the existing ones seems to be impossible.
For settings that need to be human readable and will primarily be edited by a human a yaml or json file seems fine.
If the state is both written and read by the program itself and a full fledged database seems overkill then I would use a file based database. Probably a simple key/value store like boltdb or sqlite if the data needs more structure.
I personally use boltdb in such a case, because it is very lightweight, superfast and I like its simplicity.
-- edit --
With json as a file structure the problem is that you need to write and read the entire file every single time. A edit would be a read of the entire file, unmarshalling the json, changing something in the unmarshalled object, marshalling it back to json and writing the entire file again.
Thats why I would only use this for settings that the program reads once on startup and that's it.

How to pass parameterized JSON value to the XSLT 2.0?

I have a JSON file for loading UI. Part of the file is as follows
{
"tab": "Add white space",
"name": "whitespace_Mode",
"label": "White space mode",
"type": "list",
"Value": "strict",
"values": [
"strict",
"preserve"
]
}
I have an issue to pass this value to XSLT. I need to write some transformations according UI value using XSLT. Could someone help me to find a way for this?
XSLT 2.0 does not have any support for handling JSON, so the best solution is going to depend on what other technology is available to you.
The ideal solution would be to move to XSLT 3.0 (e.g. Saxon) which has functions like json-doc(), parse-json(), and json-to-xml() which can convert this input to something that XSLT can process.
It also depends on what you want to do with the data, which you haven't made clear.