Import JSON to Flask template - json

I'm passing JSON
{
"name": "Jo",
"surname": "Sin",
"market": "US",
"date": "2020-07-07T00:00:00",
"contactPerson": {
"name": "Jan Kowalski",
"position": "Nikt",
"address": "ul. Kolorowa 123",
"phone": "736537362",
"fax": "827283738",
"email": "koko#ko.pl"
},
"secondContactPerson": {
"name": "Anna Mark",
"position": "buk",
"address": "ul. Nowowiejska 37a",
"phone": "27637222342",
"fax": "347484748",
"email": "lala#la.pl"
},
"representatives": [
{
"name": "Wojciech Makowski",
"title": "master"
}
],
"customerRepresentatives": [
{
"name": "George Soros",
"title": "bogacz"
}
]
}
templateLoader = jinja2.FileSystemLoader(searchpath="./templates/")
templateEnv = jinja2.Environment(loader=templateLoader)
TEMPLATE_FILE = "pdf_template.html"
template = templateEnv.get_template(TEMPLATE_FILE)
html = template.render(context_dict)
to Flask template and I would like to modify it for example from date I would like to get just day and month. I would like to list all representatives and more. How can I achieve it?

Try this:
{{ json.date.strftime('%A') }}

Related

I need to retrieve the index(number 1) information in mongodb compass

I just need to query all information of the doctor in the first index.
Here is my sample XML data
Here is my sample JSON data:
Both XML and JSON data are same. I just converted the XML to JSON format.
I have more documents like this.
I tried this query in this image
this query showing all information but I just need first doctors information.
I also tried in command prompt.Here is the query done in cmd
Here is my sample JSON code block: but I have more similar documents
{
"doctors": {
"doctor":[
{
"ssn": "257-79-xxxx",
"name": "Mavis Bxx",
"address": "xxxx Rusk Drive",
"country": "France",
"email": "",
"phone": "",
"patients": {
"patient": [
{
"gender": "Male",
"name": "Itch xxxx",
"address": "xx Cottonwood Avenue",
"revenue": "254",
"_country": "Spain",
"_id": "27"
},
{
"gender": "Male",
"name": "Damon xxxxx",
"address": "xx David Trail",
"revenue": "370",
"_country": "Germany",
"_id": "21"
}
]
},
"_id": "6"
},
{
"ssn": "179-45-xxxx",
"name": "Tobie Conxxxx",
"address": "x Comanche Center",
"country": "Spain",
"email": "tconringh#xxx.xxx",
"phone": "+86 998 262 xxxx",
"patients": {
"patient": {
"gender": "Male",
"name": "Vergil Tome",
"address": "x Melody Drive",
"revenue": "254",
"_country": "Germany",
"_id": "15"
}
},
"_id": "18"
},
{
"ssn": "777-59-xxxx",
"name": "Gertrud Macxxxx",
"address": "x Buell Drive",
"country": "USA",
"email": "gmaclaig2#xxx.com",
"phone": "+62 975 394 xxxx",
"patients": {
"patient": [
{
"gender": "Non-binary",
"name": "Dre Skxxxx",
"address": "x Becker Circle",
"revenue": "400",
"_country": "Germany",
"_id": "20"
},
{
"gender": "Female",
"name": "Arleyne Lestxxxx",
"address": "xx Farragut Court",
"revenue": "225",
"_country": "France",
"_id": "22"
}
]
},
"_id": "3"
}
You needs to change your collect data format. Your current format is single big size data. Not a quarriable format.
So
From current format
{
"doctors": {
"docker": [
{
...
"patients": {
"patient": [
{
...
},
{
...
}
]
},
},
{
...
}
]
}
}
To this format
[
{
...
"patients": [
{
...
},
{
...
}
]
},
{
...
}
]
Test JSON
[
{
"ssn": "2xx-7x-4xxx",
"name": "Mavis Bxxxed",
"address": "9xxx Rusk Drive",
"country": "France",
"email": "",
"phone": "",
"patients": [
{
"gender": "Male",
"name": "Itch Txxx",
"address": "5xx Cottonwood Avenue",
"revenue": "25x",
"_country": "Spain",
"_id": "27"
},
{
"gender": "Male",
"name": "Damon Wxxx",
"address": "09xx Dxxxx Trail",
"revenue": "370",
"_country": "Germany",
"_id": "21"
}
],
"_id": "6"
},
{
"ssn": "19-45-xxxx",
"name": "Tobie Coxxxx",
"address": "8x Comxxxx Center",
"country": "Spain",
"email": "tconxxxxx#usa.gov",
"phone": "",
"patients": [
{
"gender": "Male",
"name": "Some one",
"address": "1 Mexxxx Drive",
"revenue": "254",
"_country": "Germany",
"_id": "15"
}
],
"_id": "18"
}
]
In Compass View after add data upper data
Find doctor by name query
{ name: "Mavis Bxxxed" }
Find doctor by patient name
{ "patients.name": "Some one" }
If same search with this query
{ "patients.name": "Itch Txxx" }
OR
{ "patients.name": "Damon Wxxx" }
will same result to find the first docker (Mavis Bxxxed)
Due to it's patients start [ and end ]. it is array type a single size of data.
You can filter by project option
{
patients: {
$filter:
{
input: "$patients",
cond: { $eq: [ "$$patient.name", "Itch Txxx"] },
as: "patient"
}
}
}
OR shows only address
{ "patients.address" : 1 }

Couchbase N1ql query for updating new objet to JSON array

I have the following sample JSON
"address":{
"details":
[
{
"id" :<system generated UUID>,
"city" :{"type" : "string"},
"country" :{"type" : "string"},
"name" :{"type" : "string"},
"url" :{"type" : "string"},
"contacts" :
[{
"email":{"type" : "string"},
"phone":{"type" : "number"}
}]
}
]
}
I want the data to be in the following ways
Example 1:
"address":
{
"details": [
{
"id": 1234,
"city": "Medway",
"country": "United Kingdom",
"name": "Medway Youth Hostel",
"url": "http://www.yha.org.uk"
}]
}
Example 2:
"address":
{
"details": [
{
"id": 1234,
"city": "Medway",
"country": "United Kingdom",
"name": "Medway Youth Hostel",
"url": "http://www.yha.org.uk",
"contact": [
{
"email": "hari34#gmail.com",
"phone": 6789435634
}
]
}]
}
Example 3 :
"address":
{
"details": [
{
"id": 1234,
"city": "Medway",
"country": "United Kingdom",
"name": "Medway Youth Hostel",
"url": "http://www.yha.org.uk",
"contact": [
{
"email": "hari34#gmail.com",
"phone": 6789435634
},
{
"email": "sri123#gmail.com",
"phone": 9876655555
}
]
}]
}
Example 4:
"address":
{
"details": [
{
"id": 1234,
"city": "Medway",
"country": "United Kingdom",
"name": "Medway Youth Hostel",
"url": "http://www.yha.org.uk",
"contact": [
{
"email": "hari34#gmail.com",
"phone": 6789435634
}
]
},
{
"id": 3456,
"city": "Texas",
"country": "USA",
"name": "Texas Youth Hostel",
"url": "http://www.yha.org.uk",
"contact": [
{
"email": "ram123#gmail.com",
"phone": 876543219
}
]
}
]
}
I am very new to n1ql query, would anyone please help me to find the solution for inserting/Update an array to the object with in object. Example 1 is inserting an data to JSON, Example 2 is updating the data to Example 1 and follows...
1. Please help to get n1ql queries that satisfies above examples.
2. How to generate an UUID to id field in the document
1) Appends array never checks if element already exist in the array
INSERT INTO default VALUES ("k01", { "details": [ { "id": 1234, "city": "Medway", "country": "United Kingdom", "name": "Medway Youth Hostel", "url": "http://www.yha.org.uk" }] });
UPDATE default AS d SET e.contact = [ { "email": "hari34#gmail.com", "phone": 6789435634 } ]
FOR e IN d.details WHEN e.id = 1234 END
WHERE META().id = "k01";
UPDATE default AS d SET e.contact = ARRAY_APPEND(e.contact,{ "email": "sri123#gmail.com", "phone": 9876655555 })
FOR e IN d.details WHEN e.id = 1234 END
WHERE META().id = "k01";
UPDATE default AS d SET d.details = ARRAY_APPEND(d.details,{ "id": 3456, "city": "Texas", "country": "USA", "name": "Texas Youth Hostel", "url": "http://www.yha.org.uk", "contact": [ { "email": "ram123#gmail.com", "phone": 876543219 } ] })
WHERE META().id = "k01";
SELECT * from default USE KEYS["k01"];
2) USE UUID() function like below
INSERT INTO default VALUES ("k01", { "details": [ { "id": UUID(), "city": "Medway", "country": "United Kingdom", "name": "Medway Youth Hostel", "url": "http://www.yha.org.uk" }] });

Parsing JSON with arrays and structures with Coldfusion

I need to output the JSON result in HTML so that I can use it in Coldfusion. I am getting the data but I do not know how to parse the returned data so that I can use it. I am a newby so be easy on me. I don't know JSON at all and this is the first time I am trying to work work this.
<cfset qpxFields = {
"request": {
"passengers": {
"adultCount": "1"
},
"slice": [
{
"origin": "JNB",
"destination": "MRU",
"date": "2016-12-19"
}
],
"solutions": "1"
}
}/>
<cfhttp url="https://www.googleapis.com/qpxExpress/v1/trips/search?key=AIzaSyB0NN9WYmrkc2Ikq9TVGzzAD_gGoSBSbP4" method="post" result="httpResp" timeout="60">
<cfhttpparam type="header" name="Content-Type" value="application/json" />
<cfhttpparam type="body" value="#serializeJSON(qpxFields)#">
</cfhttp>
<cfset getResult = deserializeJSON(httpResp.filecontent)>
<cfoutput>#httpResp.filecontent#</cfoutput>
The result I am getting when outputting the filecontent is the following:
{ "kind": "qpxExpress#tripsSearch", "trips": { "kind": "qpxexpress#tripOptions", "requestId": "ylROS8N2kR4vI8ktC0PQVj", "data": { "kind": "qpxexpress#data", "airport": [ { "kind": "qpxexpress#airportData", "code": "JNB", "city": "JNB", "name": "Johannesburg O.R. Tambo International" }, { "kind": "qpxexpress#airportData", "code": "MRU", "city": "MRU", "name": "Mauritius Sir S. Ramgoolam International" } ], "city": [ { "kind": "qpxexpress#cityData", "code": "JNB", "name": "Johannesburg" }, { "kind": "qpxexpress#cityData", "code": "MRU", "name": "Mauritius" } ], "aircraft": [ { "kind": "qpxexpress#aircraftData", "code": "343", "name": "Airbus A340" } ], "tax": [ { "kind": "qpxexpress#taxData", "id": "EV_001", "name": "South Africa Passenger Safety Charge" }, { "kind": "qpxexpress#taxData", "id": "YQ_F", "name": "MK YQ surcharge" }, { "kind": "qpxexpress#taxData", "id": "YR_I", "name": "MK YR surcharge" }, { "kind": "qpxexpress#taxData", "id": "ZA_001", "name": "South Africa Passenger Service Charge" }, { "kind": "qpxexpress#taxData", "id": "UM_001", "name": "South Africa Asc Charge" }, { "kind": "qpxexpress#taxData", "id": "WC_001", "name": "South Africa Air Passenger Tax" } ], "carrier": [ { "kind": "qpxexpress#carrierData", "code": "MK", "name": "AIR MAURITIUS LTD" } ] }, "tripOption": [ { "kind": "qpxexpress#tripOption", "saleTotal": "ZAR5398.23", "id": "bGXAC5TFGRFO06xEFBzMaA001", "slice": [ { "kind": "qpxexpress#sliceInfo", "duration": 240, "segment": [ { "kind": "qpxexpress#segmentInfo", "duration": 240, "flight": { "carrier": "MK", "number": "852" }, "id": "GB3DFc4zHshnkF7H", "cabin": "COACH", "bookingCode": "T", "bookingCodeCount": 9, "marriedSegmentGroup": "0", "leg": [ { "kind": "qpxexpress#legInfo", "id": "LwsDBsjHUFZrYe5Y", "aircraft": "343", "arrivalTime": "2016-12-19T19:35+04:00", "departureTime": "2016-12-19T13:35+02:00", "origin": "JNB", "destination": "MRU", "originTerminal": "B", "duration": 240, "mileage": 1904, "meal": "Meal" } ] } ] } ], "pricing": [ { "kind": "qpxexpress#pricingInfo", "fare": [ { "kind": "qpxexpress#fareInfo", "id": "AdGb1tIdX7T9uIyT9qTU9OFHTXhaVL0C0ojKd7a7use6", "carrier": "MK", "origin": "JNB", "destination": "MRU", "basisCode": "TAANOWMU" } ], "segmentPricing": [ { "kind": "qpxexpress#segmentPricing", "fareId": "AdGb1tIdX7T9uIyT9qTU9OFHTXhaVL0C0ojKd7a7use6", "segmentId": "GB3DFc4zHshnkF7H" } ], "baseFareTotal": "ZAR3690.00", "saleFareTotal": "ZAR3690.00", "saleTaxTotal": "ZAR1708.23", "saleTotal": "ZAR5398.23", "passengers": { "kind": "qpxexpress#passengerCounts", "adultCount": 1 }, "tax": [ { "kind": "qpxexpress#taxInfo", "id": "ZA_001", "chargeType": "GOVERNMENT", "code": "ZA", "country": "ZA", "salePrice": "ZAR346.00" }, { "kind": "qpxexpress#taxInfo", "id": "EV_001", "chargeType": "GOVERNMENT", "code": "EV", "country": "ZA", "salePrice": "ZAR20.23" }, { "kind": "qpxexpress#taxInfo", "id": "UM_001", "chargeType": "GOVERNMENT", "code": "UM", "country": "ZA", "salePrice": "ZAR24.00" }, { "kind": "qpxexpress#taxInfo", "id": "WC_001", "chargeType": "GOVERNMENT", "code": "WC", "country": "ZA", "salePrice": "ZAR190.00" }, { "kind": "qpxexpress#taxInfo", "id": "YQ_F", "chargeType": "CARRIER_SURCHARGE", "code": "YQ", "salePrice": "ZAR1090.00" }, { "kind": "qpxexpress#taxInfo", "id": "YR_I", "chargeType": "CARRIER_SURCHARGE", "code": "YR", "salePrice": "ZAR38.00" } ], "fareCalculation": "JNB MK MRU 260.69TAANOWMU NUC 260.69 END ROE 14.15458 FARE ZAR 3690.00 XT 20.23EV 24.00UM 190.00WC 346.00ZA 1090.00YQ 38.00YR", "latestTicketingTime": "2016-12-19T06:34-05:00", "ptc": "ADT", "refundable": true } ] } ] } }
I am using CF 10.
Instead of trying to deal with the HTTP response (httpResp.filecontent) look at your deserialized content (getResult). You cannot simply output that variable as ColdFusion creates a structure from the JSON data.
Dump out your deserialzed JSON like this:
<cfdump var="#getResult#">
Looking at that output you will see how ColdFusion has already parsed all of the information for you. You are going to have some structure values and some array values. You will need to use appropriate methods (looping over an array for example) to extract each individual piece of data.
Reply to your comment
Looping in ColdFusion is well documented. To get you started you can look at the Adobe documentation itself - cfloop. The documentation on that page shows how to link over arrays, structures, etc.
Another good reference is Learn CF In a Week - looping.
Looping works when you have to traverse one-dimensional or two-dimensional structs or arrays. When the data combines structs and arrays in 3 or more dimensions, as in this particular problem, then looping is often insufficient as a solution. The complexity will certainly overwhelm most beginners.
A good solution is to play dumb. Start with the result, the structure getResult. Do a dump, as suggested by others earlier. Then simply run through it by eye and drill down to the values.
The list of values is:
getResult.kind
getResult.trips.data.aircraft[1].code
getResult.trips.data.aircraft[1].kind
getResult.trips.data.aircraft[1].name
getResult.trips.data.airport[1].city
getResult.trips.data.airport[1].code
getResult.trips.data.airport[1].kind
getResult.trips.data.airport[1].name
getResult.trips.data.airport[2].city
getResult.trips.data.airport[2].code
getResult.trips.data.airport[2].kind
getResult.trips.data.airport[2].name
getResult.trips.data.carrier[1].code
getResult.trips.data.carrier[1].kind
getResult.trips.data.carrier[1].name
getResult.trips.data.city[1].code
getResult.trips.data.city[1].kind
getResult.trips.data.city[1].name
getResult.trips.data.city[2].code
getResult.trips.data.city[2].kind
getResult.trips.data.city[2].name
getResult.trips.data.kind
getResult.trips.data.tax[1].id
getResult.trips.data.tax[1].kind
getResult.trips.data.tax[1].name
getResult.trips.data.tax[2].id
getResult.trips.data.tax[2].kind
getResult.trips.data.tax[2].name
getResult.trips.data.tax[3].id
getResult.trips.data.tax[3].kind
getResult.trips.data.tax[3].name
getResult.trips.data.tax[4].id
getResult.trips.data.tax[4].kind
getResult.trips.data.tax[4].name
getResult.trips.data.tax[5].id
getResult.trips.data.tax[5].kind
getResult.trips.data.tax[5].name
getResult.trips.data.tax[6].id
getResult.trips.data.tax[6].kind
getResult.trips.data.tax[6].name
getResult.trips.kind
getResult.trips.requestId
getResult.trips.tripOption[1].id
getResult.trips.tripOption[1].kind
getResult.trips.tripOption[1].saletotal
getResult.trips.tripOption[1].pricing[1].basefareTotal
getResult.trips.tripOption[1].pricing[1].fare[1].basiscode
getResult.trips.tripOption[1].pricing[1].fare[1].carrier
getResult.trips.tripOption[1].pricing[1].fare[1].destination
getResult.trips.tripOption[1].pricing[1].fare[1].id
getResult.trips.tripOption[1].pricing[1].fare[1].kind
getResult.trips.tripOption[1].pricing[1].fare[1].origin
getResult.trips.tripOption[1].pricing[1].fareCalculation
getResult.trips.tripOption[1].pricing[1].kind
getResult.trips.tripOption[1].pricing[1].latestTicketingTime
getResult.trips.tripOption[1].pricing[1].passengers.adultCount
getResult.trips.tripOption[1].pricing[1].passengers.kind
getResult.trips.tripOption[1].pricing[1].ptc
getResult.trips.tripOption[1].pricing[1].refundable
getResult.trips.tripOption[1].pricing[1].saleFareTotal
getResult.trips.tripOption[1].pricing[1].saletaxTotal
getResult.trips.tripOption[1].pricing[1].saleTotal
getResult.trips.tripOption[1].pricing[1].segmentPricing[1].fareId
getResult.trips.tripOption[1].pricing[1].segmentPricing[1].kind
getResult.trips.tripOption[1].pricing[1].segmentPricing[1].segmentId
getResult.trips.tripOption[1].pricing[1].tax[1].chargeType
getResult.trips.tripOption[1].pricing[1].tax[1].code
getResult.trips.tripOption[1].pricing[1].tax[1].country
getResult.trips.tripOption[1].pricing[1].tax[1].id
getResult.trips.tripOption[1].pricing[1].tax[1].kind
getResult.trips.tripOption[1].pricing[1].tax[1].salePrice
getResult.trips.tripOption[1].pricing[1].tax[2].chargeType
getResult.trips.tripOption[1].pricing[1].tax[2].code
getResult.trips.tripOption[1].pricing[1].tax[2].country
getResult.trips.tripOption[1].pricing[1].tax[2].id
getResult.trips.tripOption[1].pricing[1].tax[2].kind
getResult.trips.tripOption[1].pricing[1].tax[2].salePrice
getResult.trips.tripOption[1].pricing[1].tax[3].chargeType
getResult.trips.tripOption[1].pricing[1].tax[3].code
getResult.trips.tripOption[1].pricing[1].tax[3].country
getResult.trips.tripOption[1].pricing[1].tax[3].id
getResult.trips.tripOption[1].pricing[1].tax[3].kind
getResult.trips.tripOption[1].pricing[1].tax[3].salePrice
getResult.trips.tripOption[1].pricing[1].tax[4].chargeType
getResult.trips.tripOption[1].pricing[1].tax[4].code
getResult.trips.tripOption[1].pricing[1].tax[4].country
getResult.trips.tripOption[1].pricing[1].tax[4].id
getResult.trips.tripOption[1].pricing[1].tax[4].kind
getResult.trips.tripOption[1].pricing[1].tax[4].salePrice
getResult.trips.tripOption[1].pricing[1].tax[5].chargeType
getResult.trips.tripOption[1].pricing[1].tax[5].code
getResult.trips.tripOption[1].pricing[1].tax[5].id
getResult.trips.tripOption[1].pricing[1].tax[5].kind
getResult.trips.tripOption[1].pricing[1].tax[5].salePrice
getResult.trips.tripOption[1].pricing[1].tax[6].chargeType
getResult.trips.tripOption[1].pricing[1].tax[6].code
getResult.trips.tripOption[1].pricing[1].tax[6].id
getResult.trips.tripOption[1].pricing[1].tax[6].kind
getResult.trips.tripOption[1].pricing[1].tax[6].salePrice
getResult.trips.tripOption[1].saletotal
getResult.trips.tripOption[1].slice[1].duration
getResult.trips.tripOption[1].slice[1].kind
getResult.trips.tripOption[1].slice[1].segment[1].bookingCode
getResult.trips.tripOption[1].slice[1].segment[1].bookingCodeCount
getResult.trips.tripOption[1].slice[1].segment[1].cabin
getResult.trips.tripOption[1].slice[1].segment[1].duration
getResult.trips.tripOption[1].slice[1].segment[1].flight.carrier
getResult.trips.tripOption[1].slice[1].segment[1].flight.number
getResult.trips.tripOption[1].slice[1].segment[1].id
getResult.trips.tripOption[1].slice[1].segment[1].kind
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].aircraft
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].arrivalTime
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].departureTime
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].destination
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].duration
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].id
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].kind
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].meal
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].mileage
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].origin
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].originTerminal
getResult.trips.tripOption[1].slice[1].segment[1].marriedSegmentGroup

Data structure for a family tree with multiple partners and siblings?

I have a very basic family tree structure but I need to figure out how to make it support multiple partners and siblings without as much redundancy.
The base of the entire tree is the person that's creating the tree.
Consider this very simple structure:
{
"name": "Me",
"dob": "1988",
"parents": [
{
"name": "Gina Carano",
"dob": "1967"
},
{
"name": "Genghis Khan",
"dob": "1961"
}
],
"children": [
{
"name": "Tim",
"dob": "1992"
}
]
}
This works nicely but what if I discovered I had a half sibling named Judy (Genghis Khan loved the ladies) and a full sibling named Brian and expanded it to this?
{
"name": "Me",
"dob": "1988",
"parents": [
{
"name": "Gina Carano",
"dob": "1967"
},
{
"name": "Genghis Khan",
"dob": "1961"
}
],
"children": [
{
"name": "Tim",
"dob": "1992"
}
],
"siblings": [
{
"name": "Judy",
"dob": "1987",
"parents": [
{
"name": "Courtney Carano",
"dob": "1965"
},
{
"name": "Genghis Khan",
"dob": "1961"
}
]
},
{
"name": "Brian",
"dob": "1988",
"parents": [
{
"name": "Gina Carano",
"dob": "1967"
},
{
"name": "Genghis Khan",
"dob": "1961"
}
]
}
]
}
This does map my 2 newfound siblings but now I have a bit of redundancy in my data, as Genghis Khan is in 3 different places. I could potentially create a one level list such as this:
[
{ "id": "1", "name": "Me", "dob": "1988", "parents": [2,3], "siblings": [4,5] },
{ "id": "2", "name": "Genghis Khan", "dob": "1961", "children": [1,4,5] },
{ "id": "3", "name": "Gina Carano", "dob": "1967", "children": [1] },
{ "id": "4", "name": "Tim", "dob": "1992", "parents" : [2,3] },
{ "id": "5", "name": "Judy", "dob": "1987", "parents": [2,6] },
{ "id": "6", "name": "Courtney Carano", "dob": "1965", "children": [5] }
]
Would this work out the same way without as much redundancy? And are there any foreseeable circumstances in which there would be any limitations in terms of mapping out multiple partners with children?
Note: I figure if I keep the initial structure, I'd have to add id keys to properly identify that Genghis Khan is the same in all 3 instances.
My end goal is mapping a pedigree tree (probably in d3.js) that is visually going to be in this manner, with a line in the middle between partners going to their children.
So with the dataset above, I'm trying to render:
Almost all genealogy systems have IDs for people, so I wouldn't worry about adding/requiring that.
The traditional way of doing this is to have a Family node type as well as a Person node type. This allows multiple marriages and also gives you a place to connect information like marriage date, marriage place, etc.
person[
{ "id": "p1", "name": "Me", "dob": "1988", "parents": "f3" },
{ "id": "p2", "name": "Genghis Khan", "dob": "1961", "parents": "f1", "spouse_families": ["f2", "f3"] },
{ "id": "p3", "name": "Gina Carano", "dob": "1967", "spouse_families" : ["f3"] },
{ "id": "p4", "name": "Brian", "dob": "1992", "parents" : "f3" },
{ "id": "p5", "name": "Judy", "dob": "1987", "parents": "f2" },
{ "id": "p6", "name": "Courtney Carano", "dob": "1965", "spouse_families": ["f2"] },
{"id": "p7", "name": "Mother of Ghengis"},
{"id": "p8", "name": "Father of Ghengis"},
]
family[
{"id":"f1","marriage date":"", "parents": ["p7", "p8"],"children":["p2"]},
{"id":"f2","marriage date":"", "parents": ["p6", "p2"],"children":["p5"]},
{"id":"f3","marriage date":"", "parents": ["p3","p2"],"children":["p1", "p4"]},
]
This gives you a place to connect all the parents and children together without redundancy and lots of special casing. (Note: I corrected "Tim" to "Brian" in the data structure to match the graphic.)

Problem retrieving data from json output

I am a noob when it comes to json. The more I use it, I am starting to like it. I have a output that looks like this
[
{
"product": {
"id": "6",
"category": "Books",
"created": "2010-04-13 15:15:18",
},
"availability": [
{
"country": "United Kingdom",
"price": "$13.99",
},
{
"country": "Germany",
"price": "$13.99",
}
]
}
]
Actually I have listed only one product, But output has many products listed. I want to loop through this json output and get all the product's category, countries where they are available and price using fbjs.
I appreciate any help.
Thanks.
If your JSON is like this,
var products = [
{
"product": {
"id": "6",
"category": "Books",
"created": "2010-04-13 15:15:18",
},
"availability": [
{
"country": "United Kingdom",
"price": "$13.99",
},
{
"country": "Germany",
"price": "$13.99",
}
]
},
{
"product": {
"id": "7",
"category": "Books",
"created": "2010-04-13 15:15:18",
},
"availability": [
{
"country": "United Kingdom",
"price": "$13.99",
},
{
"country": "Germany",
"price": "$13.99",
}
]
}
]
You can iterate through:
for(var index = 0; index < products.length; index++) {
alert(products[index].product.category);
}