Consider a JSON representation for delivering a package from one address to another. Simplified,
{
"parcelId": 123,
"source": {
"street": "123 Main Street",
"city": "Anytown",
"state": "New York"
},
"destination": {
"street": "456 Avenue B",
"city": "Elsewhere",
"state": "New Jersey"
}
}
I'm fairly sure that keys "street", "city", and "state" can be legally nested in both "source" and "destination" objects. Are there technical reasons that the key names should not be repeated?
Are there technical reasons that the key names should not be repeated?
No. Seems perfectly reasonable to me.
e.g. if I was serialising a Scala/Java object, that object could look like:
class Delivery {
val parcelId : String
val source : Address
val destination : Address
}
and the field names of the Address object would be the same here.
There is nothing wrong with having duplicate property keys which are part of different objects in JSON.
Your JSON example is perfectly valid.
This is only an issue when they are at the same level.
For example two source objects:
{
"parcelId": 123,
"source": {
"street": "123 Main Street",
"city": "Anytown",
"state": "New York"
},
"source": {
"street": "456 Avenue B",
"city": "Elsewhere",
"state": "New Jersey"
}
}
Or two street properties inside one object:
"source": {
"street": "456 Avenue B",
"street": "Elsewhere",
"state": "New Jersey"
}
No. This would be confusing if you had delivery.street and then a different delivery.street. But you don't. You have delivery.source.street and delivery.destination.street. Basically the key street is addressing a completely different object now.
Related
I have to extract attributes from a json file that I receive from an api call using InvokeHTTPCustom. JSON FILE has the following sample data :
[
{
"input_index": 0,
"candidate_index": 0,
"delivery_line_1": "1 Santa Claus Ln",
"last_line": "North Pole AK 99705-9901",
"delivery_point_barcode": "997059901010",
"components": {
"primary_number": "1",
"street_name": "Santa Claus",
"street_suffix": "Ln",
"city_name": "North Pole",
"state_abbreviation": "AK",
"zipcode": "99705",
"plus4_code": "9901",
"delivery_point": "01",
"delivery_point_check_digit": "0"
},
"metadata": {
"record_type": "S",
"zip_type": "Standard",
"county_fips": "02090",
"county_name": "Fairbanks North Star",
"carrier_route": "C004",
"congressional_district": "AL",
"rdi": "Commercial",
"elot_sequence": "0001",
"elot_sort": "A",
"latitude": 64.75233,
"longitude": -147.35297,
"coordinate_license": 1,
"precision": "Rooftop",
"time_zone": "Alaska",
"utc_offset": -9,
"dst": true
},
"analysis": {
"dpv_match_code": "Y",
"dpv_footnotes": "AABB",
"dpv_cmra": "N",
"dpv_vacant": "N",
"dpv_no_stat": "Y",
"active": "Y",
"footnotes": "L#"
}
},
{
"input_index": 1,
"candidate_index": 0,
"addressee": "Apple Inc",
"delivery_line_1": "1 Infinite Loop",
// truncated for brevity
}
]
I have extracted all the required data such as address, state, city, primary_number, etc.
However, when I try to extract latitude,longitude from metadata, it leads to failure in EvaluateJsonPathAttributeCustom processor. Other attributes, which are in string format, get extracted correctly. However, this being not a string, might be issue, is my diagnosis.
How do I get this working?
I need to extract longitudes and latitudes.
Please give detail explanation as I am new to nifi.
Configuration in nifi for EvaluateJsonPathAttributeCustom:
Attribute Name Input : x**.json
Attribute Name Output : latitude
JsonPathExpresssion : $[0].metadata.latitude
Splitif.. : False
One way to do this is by using the JOLT https://jolt-demo.appspot.com/.
I would recommend using the JoltTransformJSON NiFi Processor as it can really help make things easy to pull out only the data that you want. I have tried your specific request and it will work to pull out those data. You can configure JOLT to pull any data you require and it might be easier once you get the hang of it.
[{
"operation": "shift",
"spec": {
"*": {
"metadata": {
"latitude": "latitude",
"longitude": "longitude"
}
}
}
}]
Suppose we are dealing with a JSON object where there can be multiple child nodes with the same structure, and we want to get the value of attribute B,C,D,etc. where attribute A equals a specific value. Below is an example.
{
"addresses": [{
"type": "home",
"address": "123 fake street",
"zip": "24301"
}, {
"type": "work",
"address": "346 Main street",
"zip": "24352"
}, {
"type": "PO Box",
"address": "PO BOX 132, New York, NY",
"zip": "10001"
}, {
"type": "second",
"address": "1600 Pennsylvania Ave.",
"zip": "90210"
}]}
Is there any JSON operator in PostgreSQL where I can get the zip code, where the address type is "work" or "home"? I am looking at https://www.postgresql.org/docs/current/static/functions-json.html and not finding what I'm looking for.
You need to "unnest" (i.e. normalize) the data, then you can apply a WHERE condition on it:
select t.adr ->> 'zip', t.adr ->> 'address'
from the_table
cross join lateral jsonb_array_elements(the_column -> 'addresses') as t(adr)
where t.adr ->> 'type' in ('work', 'home');
Online example: http://rextester.com/TDB99535
I am facing some issue in NYC department of building API.
help me if you know any other API giving the same information
I have used this API but didn't work for me
https://data.cityofnewyork.us/resource/83x8-shf7.json
Missing fields
permitee detailed address
https://data.cityofnewyork.us/resource/83x8-shf7.json?$where=filing_date BETWEEN '2018-05-01T06:00:00' AND '2018-05-30T10:00:00'
Also i am not able get expected data using filters for "filing_date" from same api
expected data should return all data between 2018-05-01 and 2018-05-30 for this API But i am getting only few results.
I am getting this data
[
{
"bin__": "3118313",
"bldg_type": "1",
"block": "05143",
"borough": "BROOKLYN",
"city": "BROOKLYN",
"community_board": "314",
"dobrundate": "2018-05-03T00:00:00.000",
"expiration_date": "2018-06-11T00:00:00.000",
"filing_date": "2018-05-02T00:00:00.000",
"filing_status": "INITIAL",
"gis_census_tract": "1522",
"gis_council_district": "40",
"gis_latitude": "40.641731",
"gis_longitude": "-73.966432",
"gis_nta_name": "Flatbush",
"house__": "328",
"issuance_date": "2018-05-02T00:00:00.000",
"job__": "321679046",
"job_doc___": "01",
"job_start_date": "2018-05-02T00:00:00.000",
"job_type": "A2",
"lot": "00068",
"non_profit": "N",
"owner_s_business_name": "N/A",
"owner_s_business_type": "INDIVIDUAL",
"owner_s_first_name": "MATTHEW",
"owner_s_house__": "328",
"owner_s_house_street_name": "ARGYLE ROAD",
"owner_s_last_name": "LIMA",
"owner_s_phone__": "3475968096",
"owner_s_zip_code": "11218",
"permit_sequence__": "01",
"permit_si_no": "3452932",
"permit_status": "ISSUED",
"permit_subtype": "OT",
"permit_type": "EW",
"permittee_s_business_name": "BMB BUILDER INC",
"permittee_s_first_name": "YUAN HANG",
"permittee_s_last_name": "XIAO",
"permittee_s_license__": "0612790",
"permittee_s_license_type": "GC",
"permittee_s_phone__": "9175776544",
"residential": "YES",
"self_cert": "N",
"site_fill": "NOT APPLICABLE",
"state": "NY",
"street_name": "ARGYLE ROAD",
"superintendent_business_name": "BMB BUILDER INC",
"superintendent_first___last_name": "YUAN HANG XIAO",
"work_type": "OT",
"zip_code": "11218"
}]
Expected Data should be
[{
"bin__": "1090379",
"bldg_type": "2",
"block": "00760",
"borough": "MANHATTAN",
"city": "GREAT NECK",
"community_board": "104",
"dobrundate": "2018-05-02T00:00:00.000",
"expiration_date": "2018-10-28T00:00:00.000",
"filing_date": "2018-05-01T00:00:00.000",
"filing_status": "RENEWAL",
"gis_census_tract": "111",
"gis_council_district": "3",
"gis_latitude": "40.753978",
"gis_longitude": "-73.993673",
"gis_nta_name": "Hudson Yards-Chelsea-Flatiron-Union Square",
"house__": "337",
"issuance_date": "2018-05-01T00:00:00.000",
"job__": "121187606",
"job_doc___": "01",
"job_start_date": "2016-02-19T00:00:00.000",
"job_type": "NB",
"lot": "00020",
"non_profit": "N",
"owner_s_business_name": "HKONY WEST 36 LLC",
"owner_s_business_type": "PARTNERSHIP",
"owner_s_first_name": "SAM",
"owner_s_house__": "420",
"owner_s_house_street_name": "GREAT NECK ROAD",
"owner_s_last_name": "CHANG",
"owner_s_phone__": "9178380886",
"owner_s_zip_code": "11021",
"permit_sequence__": "07",
"permit_si_no": "3451790",
"permit_status": "ISSUED",
"permit_type": "NB",
"permittee_s_business_name": "OMNIBUILD CONSTRUCTION IN",
"permittee_s_first_name": "PETER",
"permittee_s_last_name": "SERPICO",
"permittee_s_license__": "0608390",
"permittee_s_license_type": "GC",
"permittee_s_phone__": "2124191930",
"self_cert": "N",
"site_fill": "ON-SITE",
"site_safety_mgr_s_first_name": "ROBERT",
"site_safety_mgr_s_last_name": "FILIPPONE",
"special_district_1": "GC",
"state": "NY",
"street_name": "W 36 ST",
"zip_code": "10018"
}]
Combing through the JSON, it appears that these columns are not matching: permit_subtype, superintendent_business_name, superintendent_first___last_name, site_safety_mgr_s_first_name, site_safety_mgr_s_last_name, and special_district_1.
Looking at the original data sources, the columns that do not match are instances where the field is blank for that field. That is, bin__ = 1090379 does not have a permit_subtype, so it is omitted in the JSON (which is standard practice).
It will, however, be included in the CSV output since that format must include all columns: https://data.cityofnewyork.us/resource/83x8-shf7.csv?$where=filing_date%20BETWEEN%20%272018-05-01T06:00:00%27%20AND%20%272018-05-30T10:00:00%27.
This answer took a bit of digging because it wasn't immediately obvious which columns were different between the two examples. It's always helpful to over-explain to make it easier to track-down the issue.
Likewise, per the filing_date question, please include the query you're attempting to use.
I'm trying to put together a JobPosting that has multiple locations listed. In the Structured Data Type Definitions listed on the developers.google.com site, it says:
If the job has multiple locations, add multiple jobLocation properties in an array. Google will choose the best location to display based on the job seeker's query.
But I continue to get an error:
"jobLocation":[
{
"#type":"Place",
"address":{
"#type":"PostalAddress",
"streetAddress":"1366 N Mockingbird Ln.",
"addressLocality":"Abilene",
"addressRegion":"TX",
"postalCode": "79603",
}
}
{
"#type":"Place",
"address":{
"#type":"PostalAddress",
"streetAddress":"3301 South 1st Street",
"addressLocality":"Abilene",
"addressRegion":"TX",
"postalCode": "79603"
}
}
]
Missing '}' or object member name.
The item that is highlighted is the first closing bracket after the first postalCode.
Remove the comma in "postalCode": "79603",, and add a comma to separate the items in the array:
"jobLocation": [
{},
{}
]
I think you need a comma after the ] - here is how it worked for me:
"jobLocation": [
{
"#type": "Place",
"address": {
"#type": "PostalAddress",
"streetAddress": "XYZ",
"addressLocality": "XYZ",
"postalCode": "XYZ",
"addressCountry": "DE"
}
},
{
"#type": "Place",
"address": {
"#type": "PostalAddress",
"streetAddress": " XYZ",
"addressLocality": "XYZ",
"postalCode": "XYZ",
"addressCountry": "DE"
}
}
],
Most of Magento rest api methods works fine for me except POST /customers/:customer_id/addresses.
I get following error:
<error>
<data_item>
<code>400</code>
<message>"Street Address" is a required value.</message>
</data_item>
<data_item>
<code>400</code>
<message>Resource data pre-validation error.</message>
</data_item>
</error>
Error is clear saying address line is missing but I don't find anything wrong in my json request. I just converted the example XML request data from their docs into json and submitting in request body.
http://devdocs.magento.com/guides/m1x/api/rest/Resources/resource_customer_addresses.html#RESTAPI-Resource-CustomerAddresses-HTTPMethod-POST-customers--customerid-addresses
Here is my json request data:
{
"firstname": "Johny",
"lastname": "Doe",
"city": "PA",
"region": "Palau",
"postcode": "19103",
"country_id": "US",
"telephone": "611-634-1181",
"street": {
"data_item": [
"2354 Jody Road Philadelphia",
"844 Jefferson Street; 4510 Willis Avenue"
]
}
}
Please advise if anything wrong in above request.
Thanks.
Ok, this is what worked for me (maybe their docs needs to update).
{
"firstname": "Johny",
"lastname": "Doe",
"city": "PA",
"region": "Palau",
"postcode": "19103",
"country_id": "US",
"telephone": "611-634-1181",
"street":
[
"2354 Jody Road Philadelphia",
"844 Jefferson Street; 4510 Willis Avenue"
]
}