Db Json Example

0 views
Skip to first unread message

Apolonio Hicks

unread,
Aug 4, 2024, 10:28:14 PM8/4/24
to stangaldestju
Sinceyou have not shared the actual JSON that you have used and only provided a reference to the documentation, based on that, I hope you are substituting the values in it and not using as -is for e.g. using the documentation example coud result in an XSS error.

I'm looking for a simple example on how to use SlickGrid when trying to retrieve the data as JSon via jQuery.Ajax.I was also unable to find any documentation of the SlickGrid plugin and was wondering if I was just looking in the wrong places.Any help to get me started with SlickGrid would be most appreciated.


The AJAX example in the SlickGrid repository is quite complex, because it's trying to get tricky with caching, etc. For example, it keeps track of all the rows already sent and will only request new rows from the server. It's also hard coded for the specific example of Digg stories. Documentation is sorely lacking and it seems buggy with the versions 1.5+ of jQuery (which changed how ajax was handled).


If you look at the doc I shared you will see that there is an example to read from a Jason. You cannot provide the url of the json file to Parse. You need to fetch the file first and then provide the json OBJECT to the function


The JSON output from different Server APIs can range from simple to highly nested and complex. The examples on this page attempt to illustrate how the JSON Data Set treats specific formats, and gives examples of the different constructor options that allow the user to tweak its behavior. See our JSON Primer for more information.


If the data you want to extract out is not at the top-level of the JSON object, you can tell the JSON data set where to find it by using the "path" constructor option. In this example, we want to extract out all of the "batter" data:


the JSON data set uses the "path" constructor option to extract the matching data out from each object in the array. Each match then becomes a row in the data set. In this example, we want the data set to select all of the "batter" objects and flatten them into rows:


It is sometimes desirable to flatten these structures so they are also available as columns in the data set. You can use the "subPaths" constructor option to tell the JSON Data Set to include these nested structures when it flattens the top-level JSON object, or the data selected by the "path" constructor option. In this particular example, because we have not specified a "path" constructor option, the JSON data set will attempt to flatten the top-level object. Since we want to also include the data from the "image" nested structure, we specify the path to the data which is simply "image".


This example shows the use of the "path" constructor option to extract out the data items. This is nothing different from some of the previous examples, but we will build on this in the next example. An abbreviated version of the JSON data is included here for reference. You can see the full JSON data used by this example here.


In this example, we are simply going to list the types of items in our JSON object. We are going to use the "path" constructor option to select out all of the "item" objects, and then display the info we get in a table:


If you compare the results above against what you see in Example 8, the first thing you will notice is that we now have more rows then we used to. What is basically happening here is that each top-level object matched by the "path" constructor option is merged with any objects that were matched by the paths in the "subPaths" constructor option. If more than one object is matched below a given top-level object, a row is created for every object matched so that its data can be accommodated.


We get even more rows than we had in Example 9 because the "topping" path also selected multiple objects in some cases. So for every top-level object matched by the "paths" constructor option, we get 'm*n' rows, where 'm' is the number of matches by the "batters.batter" sub path, and 'n' is the number of matches by the "topping" sub path.


Sometimes you want to work with nested structures, but you don't want to deal with the explosion of rows as shown in Example 10. Imagine you want to show a list of the different types of items, and under each item, you also want to list the different types of batters and toppings available. Doing that with the data set used in Example 10 would require some JavaScript logic embedded in spry attribute conditionals to control when things showed up. A simpler approach would be to use NestedJSONDataSets.


In this example we use the same JSON data used in Example 10, but we will use 2 nested JSON data sets to track the "batter" and "topping" data. Nested data sets are special data sets that stay in sync with the current row of their parent data set. As the current row of the parent data set changes, so does the data inside of the nested data set.


The other interesting thing about nested data sets is that if their parent data set is used in a spry:repeat or spry:repeatchildren context, any data references from the nested data set are kept in sync with whatever the current row is that is being processed by the loop.


Although you can use nested data sets to produce a table that looks like the one in Example 9, there's an important difference. Nested data sets can only sort and filter within groups constrained by the parent's row it is associated with. It is easier to illustrate this with an example. In this example, we have a table that looks like the one in Example 9 on the left side, and on the right side, we have the same data presented as a set of nested lists.


Notice that when you sort any column associated with the parent data set, all of the rows in the table shift around, whereas when you click on the batter column, it seems as if only the data in the batter column is moving around. If you look at what happens in the list on the right as you sort, it becomes more apparent what is happening.


Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.


However, I just started learning PHP and I am not quite sure how PHP is linked to JSON/AJAX. For example, is it possible to edit/generate a JSON file using PHP? Overall, what part does PHP play in the overall process?


In one scenario, you could simply fetch a JSON file from the server using AJAX, but the data you fetch is static. JSON is not a scripting language, it has no logic, it doesn't do anything other than format your data.


Well, what if you wanted to fetch non-static data, like from a database, and receive it in JSON format? You need some other language to handle the process of receiving the request, access the data you asked for from the database, and return it to you in the proper format. That's where a scripting language like PHP comes in handy.


So yep, you're exactly right, PHP can edit/generate the JSON for you, and it can also handle all the routing for your website; handle form requests; AJAX requests; get data in and out of a database; and lot's of other useful things. It's a super handy and fun programming language learn.


As an example of what I wish to do, I provide some dummy JSON data that has the same nested structure. In this example, there are 2 entries coming from separate form submissions, each of which record the same questions.


As an example, it would be great if I could find a way to display this data as a simple 2x2 table, with separate rows for each of the 2 entries, and columns corresponding to the answer to questions 2 and 3 (Organization represented by speaker" and "Title of contribution"). The data comes from a url having the structure formID/submissions?apiKey=apiKey


I copied the example html code into a file named mypage.html and ftp the file to the CompactCom.

When I browse to the file ( ), the page loads with the correct title but the page is blank. I believe it should display the module name and current cpu load.

Am I wrong about that?

Am I missing something to make it work?


If this JSON file is something you intend to include as part of your Terraform configuration (e.g. checked in to version control alongside the .tf files) then you can load the data structure from it into Terraform using the file function and the jsondecode function.


The path.module reference here evaluates to the directory containing the .tf file where this expression is written, and the file must exist and contain valid JSON at the time Terraform is initially loading and validating the configuration.


If you use file and jsondecode as I showed then your Terraform configuration is self-contained: you can just run terraform apply and it will automatically find all of the data required, without the person running Terraform needing to know anything about that file. In this sense, the direct loading approach makes the JSON file an implementation detail of the Terraform configuration, rather than part of its interface.


Then in the prometheus.tpl files, you just reference the variables with the $ syntax. Here is a snippet of that json. The prometheus.tpl file is just straight json, but with a tpl extension to show it is a template.


The easiest way to use jsonencode is to just call it inline in your main configuration, but if you can also use the templatefile function to render an external Template (templatefile has replaced the template_filedata source for most uses in Terraform 0.12):


JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax. It is commonly used for transmitting data in web applications (e.g., sending some data from the server to the client, so it can be displayed on a web page, or vice versa). You'll come across it quite often, so in this article, we give you all you need to work with JSON using JavaScript, including parsing JSON so you can access data within it, and creating JSON.

3a8082e126
Reply all
Reply to author
Forward
0 new messages