JSON file to CSV or Oracle Table - json

I have to convert a JSON file in a CSV file or even better, extract the JSON file content in to an Oracle table.
I gave a look into the other topics and the only one that I found is related to the conversion in HTML table.
The files are really unstructured, here an example:
{
"message-version" : "1.2",
"orcid-profile" : {
"orcid" : null,
"orcid-id" : null,
"orcid-identifier" : {
"value" : null,
"uri" : "http://orcid.org/0000-0002-3285-9536",
"path" : "0000-0002-3285-9536",
"host" : "orcid.org"
},
"orcid-deprecated" : null,
"orcid-preferences" : {
"locale" : "EN"
},
"orcid-history" : {
"creation-method" : "MEMBER_REFERRED",
"completion-date" : null,
"submission-date" : {
"value" : 1417193651961
},
"last-modified-date" : {
"value" : 1418131422749
},
"claimed" : {
"value" : true
},
"source" : null,
"deactivation-date" : null,
"verified-email" : {
"value" : true
},
"verified-primary-email" : {
"value" : true
},
"visibility" : null
},
"orcid-bio" : {
"personal-details" : {
"given-names" : {
"value" : "Marcin"
},
"family-name" : {
"value" : "Serocki"
},
"credit-name" : null,
"other-names" : null
},
"biography" : null,
"researcher-urls" : null,
"contact-details" : null,
"keywords" : null,
"external-identifiers" : null,
"delegation" : null,
"applications" : null,
"scope" : null
},
"orcid-activities" : {
"affiliations" : {
"affiliation" : [ {
"type" : "EDUCATION",
"department-name" : "Department of Pharmaceutical Technology and Biochemistry",
"role-title" : "PhD",
"start-date" : {
"year" : {
"value" : "2010"
},
"month" : {
"value" : "09"
},
"day" : {
"value" : "01"
}
},
"end-date" : null,
"organization" : {
"name" : "Gdansk University of Technology",
"address" : {
"city" : "Gdansk",
"region" : null,
"country" : "PL"
},
"disambiguated-organization" : null
},
"source" : {
"source-orcid" : {
"value" : null,
"uri" : "http://orcid.org/0000-0002-3285-9536",
"path" : "0000-0002-3285-9536",
"host" : "orcid.org"
},
"source-client-id" : null,
"source-name" : {
"value" : "Marcin Serocki"
},
"source-date" : {
"value" : 1418131402196
}
},
"created-date" : {
"value" : 1418131402196
},
"last-modified-date" : {
"value" : 1418131402196
},
"visibility" : "PUBLIC",
"put-code" : "611828"
}, {
"type" : "EDUCATION",
"department-name" : "Department of Pharmaceutical Technology and Biochemistry",
"role-title" : "MSc",
"start-date" : {
"year" : {
"value" : "2005"
},
"month" : {
"value" : "09"
},
"day" : {
"value" : "01"
}
},
"end-date" : {
"year" : {
"value" : "2010"
},
"month" : {
"value" : "07"
},
"day" : {
"value" : "01"
}
},
"organization" : {
"name" : "Gdansk University of Technology",
"address" : {
"city" : "Gdansk",
"region" : null,
"country" : "PL"
},
"disambiguated-organization" : null
},
"source" : {
"source-orcid" : {
"value" : null,
"uri" : "http://orcid.org/0000-0002-3285-9536",
"path" : "0000-0002-3285-9536",
"host" : "orcid.org"
},
"source-client-id" : null,
"source-name" : {
"value" : "Marcin Serocki"
},
"source-date" : {
"value" : 1418131329327
}
},
"created-date" : {
"value" : 1418131329327
},
"last-modified-date" : {
"value" : 1418131329327
},
"visibility" : "PUBLIC",
"put-code" : "611826"
} ]
},
"orcid-works" : null,
"funding-list" : null
},
"orcid-internal" : null,
"type" : "USER",
"group-type" : null,
"client-type" : null
},
"orcid-search-results" : null,
"error-desc" : null
}
I have no idea how to proceed?

All code is available at github.
The code is updated according to the changed did in csv in 2013 since then CSVs now have headers! The key name for the field is now the first row of the CSV.
https://github.com/vinay20045/json-to-csv
OR
You can use api
https://json-csv.com/api to convert.
Just register there get api accessibility privileges and use thier code. That's it

Related

file_get_contents('php://input'); is not working

$json = file_get_contents('php://input');
is not returning any result
sample JSON I was supposed to get from my payment gateway is here (sorry I couldn't post sample code here please see comment)
https://uat-paco.s3.ap-southeast-1.amazonaws.com/HTML-based-docs/CorePaymentAPI/2022-04-25-Et01x9/APIs/Payment.html#_inline_response_202_data
{
"version" : "1.0.0",
"apiResponse" : {
"responseMessageID" : "fadaba8f-b02c-4ff4-a8f0-2e5ce9873185",
"responseToRequestMessageID" : "e952828c-6d19-4a08-92e4-1bc47e1945a2",
"responseCode" : "PC-B050000",
"responseDescription" : "Success",
"responseDateTime" : "2016-08-29T09:12:34.001+0000",
"responseTime" : 2400,
"marketingDescription" : "Payment is success. Thank you for purchase."
},
"data" : {
"paymentIncompleteResult" : {
"officeGroupId" : "string",
"officeId" : "string",
"transactionDateTime" : "2016-08-29T09:12:34.001+0000",
"orderNo" : "684105191128073630",
"productDescription" : "URRT55",
"invoiceNo2C2P" : "FPX054658",
"pspReferenceNo" : "W32UPVAPCP260543864232",
"controllerInternalID" : "f81d4fae-7dec-11d0-a765-00a0c91e6bf6",
"paymentStatusInfo" : {
"paymentStatus" : "A",
"paymentStep" : "PA",
"lastUpdatedDTTM" : "2016-08-29T09:12:35.001+0000"
},
"paymentType" : "CC-VI",
"paymentExpiryDateTime" : "2016-08-30T23:59:59.999+0000",
"channelCode" : "WEBPAY",
"agentCode" : "FPX_SBIA",
"mcpFlag" : "N",
"mcpDetails" : {
"mcpType" : "DCC",
"fxRate" : {
"fxRate" : 32.9,
"markUp" : 1.2,
"convertedAmount" : {
"amountText" : "000000006135",
"currencyCode" : "USD",
"decimalPlaces" : 2,
"amount" : 61.349694
},
"fxProviderId" : "FXP0001",
"fxDate" : "2016-08-29T09:12:34.001+0000"
}
},
"merchantIdForMCP" : "4572325756",
"transactionAmount" : {
"amountText" : "000000999950",
"currencyCode" : "THB",
"decimalPlaces" : 2,
"amount" : 9999.5
},
"settlementAmount" : {
"amountText" : "000000999950",
"currencyCode" : "THB",
"decimalPlaces" : 2,
"amount" : 9999.5
},
"customFieldList" : [ {
"fieldName" : "ExternalID5",
"fieldValue" : "AMADEUS"
} ],
"aresACSChallenge" : {
"transStatus" : "C",
"acsURL" : "https://uatemvco.2c2p.com/challenge",
"creq" : "Base64url encoded form data"
},
"authentication3DSVersion" : "2.1.0",
"availablePaymentTypes" : [ "CC-VI", "CC-CA" ],
"untokenizedStoredCardList" : [ {
"storedCardUniqueID" : "string",
"isExpired" : true,
"cardNumber" : "401200XXXXXX3335",
"cardExpiryMMYY" : "1124",
"cvvCode" : "123",
"payerName" : "Attasit Txxxxxx",
"issuerBankCountry" : "TH",
"issuerBankName" : "JPMORGAN CHASE BANK N.A."
} ]
},
"paymentPage" : {
"paymentPageURL" : "https://demo-paco.2c2p.com/payment/form",
"validTillDateTime" : "2016-08-29T09:12:34.001+0000"
}
}
}

Update deeply nested array in mongodb

I am trying to update field value in mongoose.
{
"_id" : ObjectId("5b62c772efedb6bd3f0c983a"),
"projectID" : ObjectId("0000000050e62416d0d75837"),
"__v" : 0,
"clientID" : ObjectId("00000000996b902b7c3f5efa"),
"inspection_data" : [
{
"pdf" : null,
"published" : "N",
"submissionTime" : ISODate("2018-08-02T08:57:08.532Z"),
"userID" : ObjectId("00000000cac68e3bc04643f7"),
"insSummary" : "inspected areas",
"insName" : "Infotech",
"_id" : ObjectId("5b62c772fa02622a18655e7b"),
"published_date" : ISODate("2018-08-02T08:57:22.041Z"),
"locationAspects" : [
{
"aspectname" : "Ground floor",
"_id" : ObjectId("5b62c772fa02622a18655e80"),
"comments" : [
{
"_id" : ObjectId("5b62c772fa02622a18655e81"),
"images" : [
{
"path" : "/uploads/inspection/00000000996b902b7c3f5efa/images/1533200242005-IpjLKH4XFWNEcHXa.png",
"img_name" : "1533200242005-IpjLKH4XFWNEcHXa.png",
"title" : "Fan",
"id" : "1"
},
{
"path" : "/uploads/inspection/00000000996b902b7c3f5efa/images/1533200242008-YN8IlA5yrMn3cBnn.png",
"img_name" : "1533200242008-YN8IlA5yrMn3cBnn.png",
"title" : "Box",
"id" : "2"
}
],
"comment" : [
"comment4"
],
"recommendation" : ""
}
]
}]
}
Here I want to update a title Fan in image array as table fan.
I tried $set but I don't know how to do for my db structure.
Kindly give some solution to this
**Updated:**
I tried this code:
mongo.inspection.update({"projectID" : mongoose.Types.ObjectId(req.body.project_id) },
{ "$set": {
"inspection_data.$[e1].locationAspects.$[e2].comments.$[e3].images.$[e4].title" : "TableFan"
}},
{ "arrayFilters": [
{ "e1._id": mongoose.Types.ObjectId(req.body.insId)},
{ "e2._id": mongoose.Types.ObjectId(req.body.aspectId)},
{ "e3._id": mongoose.Types.ObjectId(req.body.commentId)},
{ "e4.id": "1" }
]},function(err,response){
if(err){
console.log("error")
}
else{
console.log('Updated')
console.log(response)
}
})
db.adminCommand( { setFeatureCompatibilityVersion: "3.6" } )
Its showing updated but in my db there is no change. Is any mistake I did ?
You can try with arrayFilters in mongodb
var mongoose = require('mongoose')
Temp.update(
{ "_id" : mongoose.Types.ObjectId("5b62c772efedb6bd3f0c983a") },
{ "$set": {
"inspection_data.$[e1].locationAspects.$[e2].comments.$[e3].images.$[e4].title": "TableFan"
}},
{ "arrayFilters": [
{ "e1._id": mongoose.Types.ObjectId("5b62c772fa02622a18655e7b") },
{ "e2._id": mongoose.Types.ObjectId("5b62c772fa02622a18655e80") },
{ "e3._id": mongoose.Types.ObjectId("5b62c772fa02622a18655e81") },
{ "e4.id": "1" }
]}
)
Note: You have to cast _id to ObjectId

MongoDB aggregation - group and retrieve ohters fileds

i have a collection with this documents:
{
"_id" : BinData(3,"utMu84VFQk+p6LOEE3Ia3w=="),
"DepartDate" : ISODate("2017-08-14T02:00:00.000+02:00"),
"Origin" : {
"Code" : "MIL",
"City" : "Milano",
"Country" : "IT"
},
"Destination" : {
"Code" : "TIA",
"City" : "Tirana",
"Country" : "AL"
},
"ReturnDate" : ISODate("2017-08-21T18:05:00.000+02:00"),
"SearchDate" : ISODate("2017-07-15T02:00:00.000+02:00"),
"Duration" : 150,
"Price" : "376.79",
"PriceCents" : 37679,
"Currency" : "EUR",
},
{
"_id" : BinData(3,"utMu845468+p6Lertya3w=="),
"DepartDate" : ISODate("2017-08-14T02:00:00.000+02:00"),
"Origin" : {
"Code" : "AOI",
"City" : "Ancona",
"Country" : "IT"
},
"Destination" : {
"Code" : "TIA",
"City" : "Tirana",
"Country" : "AL"
},
"ReturnDate" : ISODate("2017-08-21T18:05:00.000+02:00"),
"SearchDate" : ISODate("2017-07-15T02:00:00.000+02:00"),
"Duration" : 100,
"Price" : "376.79",
"PriceCents" : 37679,
"Currency" : "EUR",
},
.........
.........
I want to group by ONLY Destination.City and return an object with
Destination.City, Destination.Code and count. Like this example:
/* 1 */
{
"_id" : {
"Code" : "PMO",
"City" : "Palermo",
"Country" : "IT"
},
"count" : 184564.0
},
/* 2 */
{
"_id" : {
"Code" : "CAG",
"City" : "Cagliari",
"Country" : "IT"
},
"count" : 130873.0
},
......
......
I tried with this query (i use MongoBooster):
db.parsed_data.aggregate([
{ "$match" : { "Destination.Country" : "IT", "Segments" : { "$elemMatch" : { "Carrier" : "AZ" } } } },
{ "$group" : { "_id" : { "City" : "$Destination.City"}, "count" : { "$sum" : 1 } } },
{ "$project" : {"Destination.Code" : 1, "Destination.City" : 1, "Destination.Country" : 1 }},
{ "$sort" : { "count" : -1 } },
{ "$limit" : 9 }])
It returns grouped by City but it shows only the City Name.
In this way:
/* 1 */
{
"_id" : {
"City" : "Lampedusa"
}
},
/* 2 */
{
"_id" : {
"City" : "Trieste"
}
},
This is not correct.
How can i group by ONLY the Destination.City and return an object with
Destination.City, Destination.Code and count?
Thx

How to apply filters on nested object array

Hello guys I'm new to angularjs.I'm trying to apply filter on the following thing.But what happening is it is not iterating all list values with ng-repeat followed by some filters.It only iterating jobseekerId 1,2 only but not 3.Where as if I'm removing the filter means it iterating all list values(1,2,3).
What is the problem with my code .Please give some suggestion.
This is my data
[ {
"jobSeekerId" : 1,
"firstName" : "vijay",
"middleName" : null,
"lastName" : "sury",
"jobSeekerProfTitle" : "Having 2.2yerars of experience in the field java development with spring and hibernate",
"profileUpdateDate" : "05 May 2014",
"currentState" : "ap",
"profilePath" : "E:/opt/jsimages/recru-profile.jpg",
"currentCity" : "hyd",
"salary" : "20000",
"salaryType" : "per month",
"jobSeekerSkillVo" : [ {
"skill" : "js"
}, {
"skill" : "java"
}, {
"skill" : "uuu"
} ],
"academicInfoVo" : [ {
"academicInfoId" : 1,
"courseName" : "btech",
"universityName" : "intuk",
"academicEndYear" : 2014,
"gpa" : 10.0
} ],
"city" : [ "hyd", "ts" ],
"totalExperience" : "48",
"viewCount" : "2",
"downloadCount" : "0",
"viewStatus" : "alive"
}, {
"jobSeekerId" : 2,
"firstName" : "raj",
"middleName" : null,
"lastName" : "sury",
"jobSeekerProfTitle" : null,
"profileUpdateDate" : null,
"currentState" : null,
"profilePath" : null,
"currentCity" : null,
"salary" : null,
"salaryType" : null,
"jobSeekerSkillVo" : [ {
"skill" : "uuu"
}, {
"skill" : "java"
} ],
"academicInfoVo" : [ {
"academicInfoId" : 2,
"courseName" : "btech",
"universityName" : "intuk",
"academicEndYear" : 2014,
"gpa" : 8.0
} ],
"city" : [ ],
"totalExperience" : "14",
"viewCount" : "1",
"downloadCount" : "0",
"viewStatus" : "alive"
}, {
"jobSeekerId" : 3,
"firstName" : "vj",
"middleName" : null,
"lastName" : "gg",
"jobSeekerProfTitle" : null,
"profileUpdateDate" : null,
"currentState" : null,
"profilePath" : null,
"currentCity" : null,
"salary" : "20000",
"salaryType" : "per month",
"jobSeekerSkillVo" : [ ],
"academicInfoVo" : [ ],
"city" : [ ],
"totalExperience" : "0",
"viewCount" : "1",
"downloadCount" : "0",
"viewStatus" : "alive"
} ]
======================
This is my filter
<div class="wrapper" ng-app="candidateListApp" ng-controller="candidateListController">
<span ng-cloak ng-repeat="jsList in jobSeekerList|filter:{jobSeekerSkillVo:
{skill:drpSkill},})}}">
<a ng-href="#">
{{jsList.firstName}} {{jsList.lastName}}
</a>
</span>
<span ng-if="jsList.jobSeekerSkillVo.length != 0">
<span ng-repeat="skills in jsList.jobSeekerSkillVo">
{{skills.skill}}
{{$last?'':','}}
</span>
</span>
</div>
<script>
var app=angular.module("candidateListApp",[]);
app.controller("candidateListController",function($scope,$http){
$scope.jobSeekerList=${jobSeekerJsonArray};
});
</script>
This is my model (with jsp code)
<select id="skills" name="skills" class="form-control2" ng-model="drpSkill">
<option value="" disabled="disabled" selected="selected">Skills</option>
<c:forEach items="${skillVo}" var="skills">
<option value="${skills.skill}">${skills.skill}</option>
</c:forEach>
</select>

How to delete a info with ID from JSON based data

The content of my JSON file is:
This is my retails.json file.actually retails is my database.i converted this json file from sql database.so in this json file, I want to delete a person information with a single ID.How can i do? i am using node.js and express.
{
"categories" : [
{
"dept_id" : "123",
"category_name" : "database",
"category_discription" : "list of database",
"current time" : "2016-07-21 06:27:17",
"id" : "1"
},
{
"dept_id" : "1234",
"category_name" : "debugging",
"category_discription" : "program debugger",
"current time" : "2016-07-21 06:32:24",
"id": "2"
},
{
"dept_id" : "12345",
"category_name" : "system analyzer",
"category_discription" : null,
"current time" : "2016-07-21 06:33:23",
"id" : "3"
}
],
"departments" : [
{
"name" : "manpreet singh",
"address_info" : "qadian",
"current time" : null,
"id" : "1"
},
{
"name" : "tushal gupta",
"address_info" : "amritsar",
"current time" : "2016-07-21 06:10:14",
"id" : "2"
},
{
"name" : "haroop singh",
"address_info" : "amritsar",
"current time" : "2016-07-21 06:11:12",
"id" : "3"
}
],
"digital_marketing" : [
{
"dept_id" : "123",
"phone" : "99889988",
"mobile" : null,
"email" : "thbs#gmail.com",
"web" : null,
"facebook" : null,
"twitter" : null,
"linkedin" : null,
"current time" : "2016-07-21 06:10:16",
"id" : "1"
},
{
"dept_id" : "1234",
"phone" : "998899888",
"mobile" : null,
"email" : null,
"web" : null,
"facebook" : "gtudgal#fb.com",
"twitter" : "tushalgupta",
"linkedin" : null,
"current time" : "2016-07-21 06:30:19",
"id" : "2"
},
{
"dept_id" : "12345",
"phone" : "99889877",
"mobile" : null,
"email" : "fhdts#mail.com",
"web" : null,
"facebook":"sdfh33#fb.com",
"twitter" : null,
"linkedin" : null,
"current time" : "2016-07-21 06:30:13",
"id" : "3"
}
]
}
I am using this to delete a ID, but does not work:
var id = 2;
app.get('/deleteUser', function (req, res) {
// First read existing users.
fs.readFile( __dirname + "/" + "retails.json", 'utf8', function (err, data) {
data = JSON.parse( data );
delete data["categories" + 2];
console.log( data );
res.end( JSON.stringify(data));
});
});
for (var prop in jsonObj.categories){
delete jsonObj.categories[prop].id;
}
similar for digital_marketing etc. jsonObj is the data in your case..