Processing JSON Records in Cold Fusion - json

First time post, so please pardon my format. Will try to provide as much detail as I can. I'm using CF 2018 and receiving a JSON file with data around employees. I can handle the API call to get it, but need some advice on how to best process it.
Here's the JSON file:
{
"Report_Entry": [
{
"Account_Group": "HEALTH GROUP",
"Group": "SERVICES GROUP",
"Employee_ID": "111111",
"Legal_Name_-_First_Name": "Ted",
"Worker_Skills_as_Text": "Programmer",
"Certification": "ICAgile Certified Professional (ICP) - The International Consortium for Agile",
"primaryWorkEmail": "ted_smith#abc.com"
},
{
"Account_Group": "FINANCE GROUP",
"Group": "INNOVATION TEAM",
"Employee_ID": "222222",
"Legal_Name_-_First_Name": "Mary",
"Worker_Skills_as_Text": "Analyst",
"Certification": "PMP; Writing Master",
"primaryWorkEmail": "mary_smith#abc.com"
},
{
"Account_Group": "ENERGY GROUP",
"Group": "BUSINESS DEVELOPMENT TEAM",
"Employee_ID": "333333",
"Legal_Name_-_First_Name": "John",
"Worker_Skills_as_Text": "Developer",
"Certification": "Certified Scrum Master (CSM) - Scrum Alliance; Certified Scrum Product Owner (CSPO) - Scrum Alliance",
"primaryWorkEmail": "john_smith#abc.com"
}
]
}
When I deserialize it returns as as:
I need to be able to loop through the structure, arrays, and the structure to capture the values then process them (i.e., insert into a table, compare to existing data, etc.). I know I need to loop through the entire thing but can't come up with the right syntax with error.
Any help or examples would be greatly appreciated.
Thanks
Jim

Here is what I've been using for dealing with something similar:
Based on your dump, you have a struct with an array of structs.
the following is a snippet that should return the first element of the array, which is a struct:
myStruct = Report_entry[1];
for (currentKey in myStruct) {
writedump(currentKey);
writedump(myStruct[currentKey]);
writeoutput('<hr>');
}
you want to get the syntax of looping over arrays and looping over structs.
CFDUMP is your friend.
I'd be happy to help with syntax. I recognize I did not provide a complete solution, but you are a little closer.

Related

Parsing a very complex json response in dart

I'm trying to load a json file from a server response and parsing it in flutter, the model i create is working for all the other fields but i'm in trouble with this class
this is a part of the JSON response:
"episodes": {
"1": [
{
"id": "63",
"episode_num": 1,
"title": "Some Name",
"container_extension": "mp4",
"info": {
"director": "",
"plot": "",
"cast": "",
"rating": "",
"releasedate": "",
"movie_image": "",
"genre": "",
"duration_secs": 6495,
"duration": "01:48:15"
}
}
]
}
in this case the entry under episodes is just one but this will represents a season and all the episode inside it, so under episodes many of this entry (undefined number during coding) can be present
At this time, using online json to dart converter tools i can be able to retrive just this one entry but if a response have more than 1 season i can't see it.
There is any way to handle this?
EDIT:
Solved using a for cicle with max value = (json['episodes'].length + 1).
For the info stored inside each 'episodes' value i can use
json['episodes']['$i']
Valid JSON is always convertible to a Dart data structure. But what you may be asking is "can I get nested objects from this?", and that just depends on how hard you want to work. Some JSON-to-Dart tools are better than others and some JSON values are impossible for any automated tool to make sense of. Only real answer is: "it depends".

How to push this JSON to firestore and query the data?

i would like to ask how do we push the JSON below into firestore in Angular?
var customer =
{
"name": "john",
"address": "xxxxx",
"order": {
"bookList": [{
"quantity": "3",
"price": "$2"
},
{
"quantity": "4",
"price": "$1"
}]
}
}
At the same time, i would like to with each address, get the list of all orders from all customers. Was thinking of doing like the json below, i will get the document ID for the orders using the client's document id then i will add to the orders array.
var data2 = {
"address": "xxxxx",
"orders": [{
"id": "1dsd"
},
{
"id": "312312"
}]
}
Im quite unsure on how to achieve these, appreciate any help and advice! It would be great if step by step instructions and explanations are provided!
Thank you!
This article provides a great example of how to import JSON data into Firestore. The user provides a quick tutorial on how to migrate your initial database to Firestore.
I would also like to encourage you to look through this tutorial of using Cloud Firestore in Angular with Angularfire as they will be best suited for what you may be looking for.
Additionally, I would like to point you towards the Angularfire community on Github, as they may provide some insight on your particular implementation. This segment of their documentation discusses ways of querying strategies that you may find useful .

Search parameter not working with the API request

I am new to json and APIs.
This particular dataset I am working with (https://api.cdnjs.com/libraries) is searchable by placing ?search=search_term after it (like: https://api.cdnjs.com/libraries?search=cloud). But when I use another json dataset (http://api.nobelprize.org/v1/prize.json for instance) it gives an error:
{ "error":"Using an unknown parameter" }
Does this have to do with how the datasets are set up? Methods perhaps? How do I make the other json searchable like the initial one (so I can use it in my search app)?
Navigating to the main domain of the provided url, you will find that the doc reside at https://nobelprize.readme.io/v1.0
To refine your results, as the docs suggest you should use the following parameters (when searching for prizes): year, yearTo, category and numberOfLaureates.
Here is an example of a refined search:
Request url: http://api.nobelprize.org/v1/prize.json?category=physics&year=2017
Response:
{
"prizes": [{
"year": "2017",
"category": "physics",
"laureates": [{
"id": "941",
"firstname": "Rainer",
"surname": "Weiss",
"motivation": "\"for decisive contributions to the LIGO detector and the observation of gravitational waves\"",
"share": "2"
}, {
"id": "942",
"firstname": "Barry C.",
"surname": "Barish",
"motivation": "\"for decisive contributions to the LIGO detector and the observation of gravitational waves\"",
"share": "4"
}, {
"id": "943",
"firstname": "Kip S.",
"surname": "Thorne",
"motivation": "\"for decisive contributions to the LIGO detector and the observation of gravitational waves\"",
"share": "4"
}]
}]
}
If it wasn't clear enough, I made a request to the API to retrieve data concerning prizes awarded in the physics category in the year 2017.

Best way to structure json data with backbone

I'm just about to write a web app using backbone and want to know what's the best way to structure my json file? I've read that using 'dictionary' arrays are best but was wondering if there's a better way of structuring the data. An example of how the data should be structure would be great too.
My data seems to have a lot of nested arrays and these seem to be hard to search through.
JSON has two types of relevant container objects.
Object and Array.
Object is probably what you're thinking of when you say "dictionary array".
You probably want an object with arrays of objects :)
{"courses": [{
"name": "Spanish 101",
"subject": "How to speak Spanish",
}, {
"name": "Introduction to Film",
"subject": "Make pretty films",
}, {
"name": "Social Psychology",
"subject": "Why people are weird.",
}],
"sections": [],
"modules": [],
"topics": [],
"lessons": [],
// etc..
}
Each of the [] items would be field with numerous objects.
Once you get this data into your APP (either JSONP, AJAX, or if it's just assinged to a variable in our page) you can put them in your Backbone collections using the reset function (See: http://backbonejs.org/#Collection-reset):
var Courses = new Backbone.Collection;
function processData(data) {
Courses.reset(data.courses);
// etc...
}

Freebase MQL to list out all commons types for a given word?

I'm trying to figure out how to write a MQL query to get a list of all the types associated to a given word.
For example I tried:
{
"id":null,
"name":null,
"name~=": "SOME_WORD",
"type":"/type/type",
"domain": {
"id": null,
"/freebase/domain_profile/category": {
"id": "/category/commons"
}
}
}​
I found this to list out all the Commons types or categories but haven't yet figured out how to narrow it down for a given input.
[{
"id": null,
"name": null,
"type": "/freebase/domain_profile",
"category": {
"id": "/category/commons"
}
}]​
There are a couple of different ways to do this with different tradeoffs for each.
Use the Search API with a query like this
https://www.googleapis.com/freebase/v1/search?indent=true&filter=%28all%20name{full}:%22uss%20constitution%22%29
You'll get back JSON results which look like this:
{
"status": "200 OK",
"result": [
{
"mid": "/m/07y14",
"name": "USS Constitution",
"notable": {
"name": "Ship",
"id": "/boats/ship"
},
"lang": "en",
"score": 1401.410400
},
...
You can make the matching more liberal by switching the "{full}" to "{phrase}" which will give you a substring match instead of an exact match.
Caveats:
- You'll only get a single "notable type" and it's fixed by Freebase's (unknown) algorithm
- I don't think there's a way to get both USS Constitution & U.S.S. Constitution results
- You can get a list of all types by adding &mql_output={"type":[]}, but then you lose the "notable" type. I don't think there's a way to get both in a single call.
Use MQL
This query returns the basic information that you want:
[{
"name~=":"uss constitution",
"type":[],
"/common/topic/notable_types" : []
}]​
Caveats:
It won't find "uss constitution" which is an alias rather than the primary name (there's a recipe in the MQL cookbook for that though)
It won't find "u.s.s. constitution"
The "notable_types" API is an MQL extension and MQL extensions aren't supported in the new Freebase API, only the legacy deprecated API
You're tied to whatever (unknown) algorithm Freebase used to compute "notability"
Depending on what you are trying to accomplish, you might need something more sophisticated than this (as well as a deeper understanding of what's in Freebase), but this should get you going with the basics.
Did you try:
[{
"name": "David Bowie",
"type": []
}]