Ideas how to store code snippets/objects (not json) in mongodb? - json

So let's say I am doing converting csv to json in node.js, and doing mapping between the fields found in the customer's input file and the object that my platform requires, such as:
var objInvoice = {
"id" : guid.create().value,
"financingType" : "scf",
"batchId" : batchId,
"recordTypeCode" : inv.kayittipi,
"buyerReference" : result[0].tedarikcireferans,
"supplierReference" : inv.tedarikcireferans,
"invoiceDate" : moment(inv.faturatarih +"-140000" , "YYMMDD-HHmmss").toISOString(),
"certifiedInvoiceAmount" : inv.odenecekfaturatutar,
"currencyCode" : inv.parabirimi,
"maturityDate" : moment(inv.orjvadetarihi +"-140000" , "YYMMDD-HHmmss").toISOString(),
"correctedMaturityDate" : moment(inv.orjvadetarihi +"-140000" , "YYMMDD-HHmmss").toISOString(),
"originalInvoiceAmount" : inv.orjfaturatutar,
"invoiceNo" : inv.faturano,
"invoiceSerialNo" : inv.faturaserino,
"noterizedDocNo" : inv.belgenoteryevmiyeno,
"hashCode" : inv.hashCode,
"forecastDate" : inv.fiilivadetarihi,
"supplierTaxId" : inv.tedarikcivkn,
"supplierName" : inv.tedarikciadi,
"invoiceType" : inv.faturatipi,
"buyerAccountNumber" : inv.aliciiban,
"buyerTaxId" : inv.alicivkn,
"fiReference" : inv. bankakodu,
"bankBranchCode" : inv.bankasubeno,
"invoiceUploadStatus" : inv.dosyakayitstatu,
"gwCode" : "111110000000",
"gwCodeExplanation" : "",
"invoiceDiscountDate" : null,
"additionalInformation1" : inv.aciklama1,
"additionalInformation2" : inv.aciklama2,
"additionalInformation3" : inv.aciklama3,
"lastModificationDate" : null,
"newInvoiceId" : "00000000-0000-0000-0000-000000000000",
"oldInvoiceId" : "00000000-0000-0000-0000-000000000000",
"supplierIban" : "",
"supplierBankName" : "",
"customUniqueId" : "",
"deductionReason" : "",
"paymentObligationNo" : null,
"deductionAmount" : "",
"sellAmount" : "",
"invoiceAmountWithoutVat" : "",
"uploadDate" : now.toISOString(),
}
but a customer2 may have a different positioned fields,or even different headers in file - such as:
var objInvoice = {
"id" : guid.create().value,
"financingType" : "scf",
"batchId" : batchId,
"recordTypeCode" : inv.element1,
"buyerReference" : result[0].element2,
"supplierReference" : inv.element2,
"invoiceDate" : moment(inv.element3 +"-140000" , "YYMMDD-HHmmss").toISOString(),
"certifiedInvoiceAmount" : inv.element4,
"currencyCode" : inv.element5,
"maturityDate" : moment(inv.element6 +"-140000" , "YYMMDD-HHmmss").toISOString(),
"correctedMaturityDate" : moment(inv.element6 +"-140000" , "YYMMDD-HHmmss").toISOString(),
"originalInvoiceAmount" : inv.element7,
"invoiceNo" : inv.element8,
"invoiceSerialNo" : inv.element9,
"noterizedDocNo" : inv.element10,
"hashCode" : inv.element11,
"forecastDate" : inv.element12,
"supplierTaxId" : inv.element13,
"supplierName" : inv.element14,
"invoiceType" : inv.element15,
"buyerAccountNumber" : inv.element16,
"buyerTaxId" : inv.element17,
"fiReference" : inv. element18,
"bankBranchCode" : inv.element19,
"invoiceUploadStatus" : inv.element20,
"gwCode" : "111110000000",
"gwCodeExplanation" : "",
"invoiceDiscountDate" : null,
"additionalInformation1" : inv.element21,
"additionalInformation2" : inv.element22,
"additionalInformation3" : inv.element23,
"lastModificationDate" : null,
"newInvoiceId" : "00000000-0000-0000-0000-000000000000",
"oldInvoiceId" : "00000000-0000-0000-0000-000000000000",
"supplierIban" : "",
"supplierBankName" : "",
"customUniqueId" : "",
"deductionReason" : "",
"paymentObligationNo" : null,
"deductionAmount" : "",
"sellAmount" : "",
"invoiceAmountWithoutVat" : "",
"uploadDate" : now.toISOString(),
}
so I was thinking if it's possible to store each 'mapping' per customer in mongodb? and pulls the correct objInvoice via customer reference?
The issue is, objInvoice cannot be stored as a json document since it contains variables such as inv.element1.
I've also tried to store as a one big string (I tried with {} and without {} ), I was able to store it fine but when I pulled it from the code and unstringnified it the vars didn't get processed as expected.
Any ideas fellow good programmers?
Or the only way is to store those in seperate js files per customer?

Unfortunately, your data is not even valid Javascript Objects or JSON.
An idea is to convert values, like moment(inv.orjvadetarihi +"-140000" , "YYMMDD-HHmmss").toISOString() which are not valid, into strings (escaping correctly). As a result you will be able to JSON.stringify and JSON.parse. The strings can then be evaluated in your code.
Preprocessing your data to escape non-string values into strings certainly works. You may use regexes.

Related

How to read Json file and convert it to dataframe

I was trying to read the JSON file and convert to JSON, but I am finding difficulties here as i dont have much knowledge on this.
from pandas.io.json import json_normalize
import pandas as pd
import json
Path = "NavigatorInstances.json"
with open(Path, 'r') as myfile:
data= myfile.read()
data = json.loads(data)
df = pd.DataFrame.from_dict(json_normalize(data))
I am getting error as: json.decoder.JSONDecodeError: Expecting value: line 2 column 13 (char 15)
My JSON Sample data looks like below
{
"_id" : ObjectId("5ecfe5a0f9fcb510c8ec51e5"),
"RNI_Corps" : {
"MetaData" : {
"TaxonomyName" : "RN.Corps",
"InstanceName" : "Ratings Navigator Instance Corps",
"ThisMongoObjectId" : "5ecfe5a0f9fcb510c8ec51e5",
"ThisObjectShortId" : "37187",
"ReplacedMongoObjectId" : "",
"ThreadIDs" : "5ecfe5a0f9fcb510c8ec51e5",
"CurrentWF_Activity" : "Drafted",
"CurrentWF_ActivityDate" : "2020-05-28 16:23:53",
"VersionID" : {
"Tool" : "RN",
"Group" : "Corps",
"Sector" : "GenCos",
"Version" : "2.8.1.1"
},
"Cart" : {
"Id" : null,
"Status" : null,
"StatusDate" : null,
"Locked" : null
},
"Effective" : {
"Date" : null,
"Reason" : null,
"Source" : {
"SystemName" : null,
"SystemId" : null,
"EventType" : null
}
},
"Criteria" : {
"Id" : "10123001",
"Name" : "Exposure Draft: Sector Navigators",
"Date" : "2020-05-20 00:00:00"
},
"InstanceFileInfo" : {
"MongoObjectId" : "5ecfe5a0f9fcb510c8ec51df",
"MD5CheckSum" : "2d28eabe1a046f76e17a58cca6c386f1",
"Name" : "RN_2_8_1_1_96781051_2020_05_28_1.xlsm",
"SavedDate" : "2020-05-28 16:24:00"
},
"EntityInfo" : {
"AgentID" : NumberInt(1507132),
"AgentName" : "AES Mexico Generation Holdings, S. de R.L. de C.V.",
"NicknameID" : null,
"Nickname" : null,
"IssuerID" : NumberInt(96781051),
"IssuerName" : "AES Mexico Generation Holdings, S. de R.L. de C.V.",
"Region" : "Emerging Markets - Americas",
"CountryName" : "Mexico",
"Sovereign_Agent_ID" : null,
"Sector" : "GenCos"
},
Please help me to understand how I can convert the JSON data into a readable format such as pandas dataframe
Your sample is not in the JSON standard(or it is only a sample?).
The word "ObjectId" is not a string or number.
I think you can try https://www.json.cn to verify your JSON file first. This error is about json not DataFrame.

Firebase API REST cant filter data using orderBy [duplicate]

This question already has answers here:
How to perform sql "LIKE" operation on firebase?
(5 answers)
Closed 4 years ago.
i'm trying to filter the data that i have in a database in firebase.
I have a very simple structure of data like this.
{
"articulos" : {
"-LHYw-qz8fiTSg03TuYS" : {
"descripcion" : "refgre",
"fabricante" : "gerg",
"iva" : "21%",
"margen" : "23",
"nombre" : "greerfg",
"preciocompra" : "3213",
"preciocompraiva" : "12312",
"precioventa" : "323",
"precioventaiva" : "23",
"ref" : "4greg"
},
"-LHYwfIIoN46cjlF3VTR" : {
"descripcion" : "gdfgdfg",
"fabricante" : "dfgdf",
"iva" : "21%",
"margen" : "45",
"nombre" : "gfdgdf",
"preciocompra" : "4345",
"preciocompraiva" : "543",
"precioventa" : "543",
"precioventaiva" : "45",
"ref" : "43g34g"
},
"-LHYwvK6xAQeXHQVrmtt" : {
"descripcion" : "fdsf",
"fabricante" : "fdsf",
"iva" : "21%",
"margen" : "34",
"nombre" : "dfsfsd",
"preciocompra" : "sdfsd",
"preciocompraiva" : "dfsd",
"precioventa" : "43",
"precioventaiva" : "34",
"ref" : "432"
}
},
"clientes" : {
"-LHjGlhQD4iP9DOsGgvx" : {
"ciudad" : "rtbrtbrt",
"comentarios" : "gfdgfd",
"correo" : "brt#hotmail.com",
"cp" : "43243",
"direccion" : "tbrb",
"dni" : "rtbrtb",
"id" : 2,
"nombre" : "5brtbtrb"
},
"-LHjHImLC3UBW3M2Rf3_" : {
"ciudad" : "fmdkjsf",
"comentarios" : ".comsfdasa",
"correo" : "dkfmsldfm#jnfdjsn",
"cp" : "32434",
"direccion" : "fkdmfkjsd",
"dni" : "mklrmg",
"id" : 2,
"nombre" : "gkjsdnfgd"
}
}
}
i have been reading the documentation, and i have read about indexOn.
Currently i have this rules.
{
"rules": {
".read": true,
".write": true,
"clientes": {
".indexOn": ["nombre"]
}
}
}
I'm not sure if i'm doing it well.. but when i send de URL,
/clientes.json?orderBy="nombre"&startAt=x
it is retrieving all the "clientes" that i have in the DataBase...
How i supposed to do it for receive all the "clientes" that start at "x"... i'm trying to develop a search input in my website...
When I add your JSON to my database, it works as expected:
https://stackoverflow.firebaseio.com/51471121/clientes.json?orderBy="nombre"&startAt="x"
Gives me no results, because there is no name starting with x or later.
But:
https://stackoverflow.firebaseio.com/51471121/clientes.json?orderBy="nombre"&startAt="f"
Gives me one result, since "nombre" : "gkjsdnfgd" is after f.

Extract JSON value using Jmeter

I have this JSON:
{
"totalMemory" : 12206567424,
"totalProcessors" : 4,
"version" : "0.4.1",
"agent" : {
"reconnectRetrySec" : 5,
"agentName" : "1001",
"checkRecovery" : false,
"backPressure" : 10000,
"throttler" : 100
},
"logPath" : "/eq/equalum/eqagent-0.4.1.0-SNAPSHOT/logs",
"startTime" : 1494837249902,
"status" : {
"current" : "active",
"currentMessage" : null,
"previous" : "pending",
"previousMessage" : "Recovery:Starting pipelines"
},
"autoStart" : false,
"recovery" : {
"agentName" : "1001",
"partitionInfo" : { },
"topicToInitialCapturePosition" : { }
},
"sources" : [ {
"dataSource" : "oracle",
"name" : "oracle_source",
"captureType" : "directOverApi",
"streams" : [ ],
"idlePollingFreqMs" : 100,
"status" : {
"current" : "active",
"currentMessage" : null,
"previous" : "pending",
"previousMessage" : "Trying to init storage"
},
"host" : "192.168.191.5",
"metricsType" : { },
"bulkSize" : 10000,
"user" : "STACK",
"password" : "********",
"port" : 1521,
"service" : "equalum",
"heartbeatPeriodInMillis" : 1000,
"lagObjective" : 1,
"dataSource" : "oracle"
} ],
"upTime" : "157 min, 0 sec",
"build" : "0-SNAPSHOT",
"target" : {
"targetType" : "equalum",
"agentID" : 1001,
"engineServers" : "192.168.56.100:9000",
"kafkaOptions" : null,
"eventsServers" : "192.168.56.100:9999",
"jaasConfigurationPath" : null,
"securityProtocol" : "PLAINTEXT",
"stateMonitorTopic" : "_state_change",
"targetType" : "equalum",
"status" : {
"current" : "active",
"currentMessage" : null,
"previous" : "pending",
"previousMessage" : "Recovery:Starting pipelines"
},
"serializationFormat" : "avroBinary"
}
}
I trying using Jmeter to extract out the value of agentID, how can I do that using Jmeter, what would be better ? using extractor or json extractor?
what I am trying to do is to extract agentID value in order to use it on another http request sample, but first I have to extract it from this request.
thanks!
I believe using JSON Extractor is the best way to get this agentID value, the relevant JsonPath query will be as simple as $..agentID
Demo:
See the following reference material:
JsonPath - Getting Started - for initial information regarding JsonPath language, functions, operators, etc.
JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios - for more complex scenarios.

Extract JSON response in JMeter

I am using JMeter and I want to extract a particular value from a JSON response and use this value in subsequent request. I have the JSON Extractor Plugin installed but I am able to drill down to the JSON value.
Below is an example JSON response captured from JMeter.
while(1);
{
: "results":
: [
: : {
: : : "permissions":
: : : [
: : : ],
: : : "exchangeId":"5wFrZHS8Obbw_JJOsaxy7A",
: : : "documentIncomplete":false,
: : : "dateCreated":1453718307090,
: : : "finalized":false,
: : : "voided":false,
: : : "certified":false,
: : : "dateModified":1453718307090,
: : : "metaData":
: : : [
: : : ],
: : : "documentCreated":false,
: : : "orphaned":false,
: : : "dynamicName":false,
: : : "description":"",
: : : "mode":"ADHOC",
: : : "state":"WITHOUT_DOCUMENT",
: : : "name":"01/25/2016 10:38:21",
: : : "priority":"C"
: : }
: ],
: "responseTime":1453718307090
}
I've tried the below but still can't get the exchangeId:
$.permissions[2].exchangeId
$.while..exchangeId
$.permissions.exchangeId
$.results.permissions.exchangeId
$.while.results.permissions.exchangeId
$.while.results[*].permissions.exchangeId
$.while.results[1].permissions[0].exchangeId
Am I doing something wrong here? Any help here is appreciated, I tried searching and couldn't find anything that relates to my problem.
This is not a valid JSON, go for Regular Expression Extractor instead, the relevant configuration would be:
Reference Name: anything meaningful, i.e. exchangeId
Regular Expression: "exchangeId":"(.+?)"
Template: $1$
You will be able to access extracted value as ${exchangeId} where required.
Demo:
References:
Regular Expressions
Using RegEx (Regular Expression Extractor) with JMeter

How to add Timestamp to Spring-Data-Mongo in Roo?

I have a Spring Roo project I am trying to create based on log4mongo-java appender and I want to get access to the data entries that looks like:
{
"_id" : ObjectId("4f16cd30b138685057c8ebcb"),
"timestamp" : ISODate("2012-01-18T13:46:24.704Z"),
"level" : "INFO", "thread" : "catalina-exec-8180-3",
"message" : "method execution[execution(TerminationComponent.terminateCall(..))]",
"loggerName" :
{ "fullyQualifiedClassName" : "component_logger",
"package" : ["component_logger"],
"className" : "component_logger"
},
"properties" : {
"cookieId" : "EDE44DC03EB65D91657885A34C80595E"
},
"fileName" : "LoggingAspect.java",
"method" : "logForComponent",
"lineNumber" : "81", "class" : {
"fullyQualifiedClassName" : "com.comcast.ivr.core.aspects.LoggingAspect",
"package" : ["com", "comcast", "ivr", "core", "aspects", "LoggingAspect"],
"className" : "LoggingAspect"
},
"host" : {
"process" : "2220#pacdcivrqaapp01",
"name" : "pacdcivrqaapp01",
"ip" : "24.40.31.85"
},
"applicationName" : "D2",
"eventType" : "Development"
}
The timestamp looks like:
"timestamp" : ISODate("2012-01-17T22:30:19.839Z")
How can I add a field in my Logging domain object to map this field?
That's just the JavaScript Date (according to the mongo docs, and as can be demonstrated in the shell), so try with java.util.Date.