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

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 .

Related

OpenAI/Codex: Can I create a fine-tuned model for Codex?

I'd like to translate user requests into tickets in some sort of structured data format, e.g. JSON. For example:
User: I want to order two chairs and a desk with three drawers on the left side.
Output:
{
"type": "furniture",
"items": [
{ "type": "desk", "qty": 1, "included_items": [{ "type": "drawer", "qty": 3, "position": "left" }] },
{ "type": "chair", "qty": 2 }
]
}
It looks like GPT3 itself is not very-well suited for this task, because output is not in the form of natural language, however Codex might be? But I can't find in OpenAI docs how I can (if it's possible at all?) to create a custome/fine-tuned model for Codex?
#xara Codex does not support a way to fine tune their model.
What you can do is prompt engineering.
Provide the model some demonstrations and try out whether Codex can perovide you with expected output.
It is currently in beta, but you can fine-tune the OpenAI codex model on your custom dataset for a charge to improve its performance. Please refer to the following link for details instruction: https://beta.openai.com/docs/guides/fine-tuning

Processing JSON Records in Cold Fusion

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.

How to build One-To-Many relationships within JSON API

I`m very new to JS/APIs/JSON.
I`ve got an API I built using deployd, a great tool that allows to to quickly set up an API.
My API called "app" has two resources zips and people. Each entry/object in zips has only one property zipcode. Each people has the properties name and phonenumber.
I want to figure out a way to have people be associated with various zipcodes. Either one or many if necessary. This would, as I understand, involve adding a property to people such as assoczipcodes and using a relationship model to indicate with zipcodes are related.
I've done some research here about how a relationship is structured but I simply don't understand the syntax and format.
Q: What datatype is correct for associzipcodes?
Q: What do I enter into each assoczipcodes to indicate which zips are related?
Cristik's answer appears to be outdated. According to the current documentation, you'd want to nest the relationship like this:
{
"type": "people",
"id": "1",
"attributes": {
"name": "John Doe"
},
"relationships": {
"zipcodes": {
"links": {
"self": "http://myserver.com/people/1/zipcodes"
}
}
}
}
Based on the contents from the Resource Relationships section, the simplest approach would be to return an URL for the relationship, and have that URL return all information needed:
{
"type": "people",
"id": "1",
"name": "John Doe",
"links": {
"zipcodes": "http://myserver.com/people/1/zipcodes"
}
}

Ember - how to represent this json in a model

I'm an ember newbie.. and have been given a spec that says the server will be sending me the following json:
{
"classname": "class1",
"studentSummary": [
{
"firstName": "test",
"lastName": "test",
"score": "45",
},
...
]
}
I've been trying to figure out how to represent this as a model and create fixture data to work with it...
I understand how to create a model with the multiple records are all the same....
var students = DS.Model.extend({
firstName: DS.attr('string'),
lastName: DS.attr('string'),
score: DS.attr('number')
});
Which would correspond to a bunch of students like this, right?:
{
[
{
"firstName": "test",
"lastName": "test",
"score": "45",
},
...
]
}
Or would it?
I'm googleing like mad but don't know if I should be looking at 'embedding' or 'hasMany' or what....
I'm thinkling the hasMany won't work without id's...
So, any push in the right direction would be appreciated...
Thanks
Vida
What you're looking for are embedded records (or so they're called). Your data doesn't have a unique identifier and it belongs only to it's parent record, so moving the data to its own model would be overkill. Embedded records are a sore subject in the Ember-Data community, but there are solutions. Here is the official EmbeddedRecordsMixin and here is a project that makes it easier to work with. Either of those should help you out.
If you're having trouble with those, you might want to consider writing a custom Transform for your data. It's more low-level, but it gives you more control and its easier to understand (I think).

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...
}