My nodejs code receives a response from a HTTP POST call which is in xml. I convert it to json using xml2js, and now I need to read this so as to get the data of one of the json keys.
This is how a part of my json data looks. I am trying to read this as follows:
var base64encoded = jsonxml."soapenv:Body".runReportResponse.runReportReturn.reportBytes;
However, when I run this i get the error message:
jsonxml."soapenv:Body".runReportResponse.runReportReturn.reportBytes;
^^^^^^^^^^^^^^
SyntaxError: Unexpected string.'
I have also tried by removing the double quotes, but then it gives exception to the colon (:) which appears in the data. How do I read such kind of data?
Entire json:
[
{
"Envelope": {
"$": {
"xmlns:soapenv": "http://schemas.xmlsoap.org/soap/envelope/",
"xmlns:xsd": "http://www.w3.org/2001/XMLSchema",
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance"
},
"Body": {
"runReportResponse": {
"$": {
"xmlns": "http://xmlns.oracle.com/oxp/service/PublicReportService"
},
"runReportReturn": {
"metaDataList": {
"$": {
"xsi:nil": "true"
}
},
"reportBytes": "MzAwMDAwMDA0Mzk5ODEwLERDT0cgQ29ycG9yYXRlIEJVDQozMDAwMDAwMDk0ODE4MzEsREVMRlRMQUJfVVNfQlVTSU5FU1NfVU5JVA0KMzAwMDAwMDAzMDYyNTI1LERFTEhJVEVDSF9VU19CVVNJTkVTU19VTklUDQozMDAwMDAwMDMwNjE1ODMsREVMTFMgVVMgQlUNCjMwMDAwMDAwMzE3OTE0NixERUxNRkcgVVMgQlUNCjMwMDAwMDAxMDI1NDA1NyxESEMgQ29ycG9yYXRlDQo=",
"reportContentType": "text/plain;charset=UTF-8",
"reportFileID": {
"$": {
"xsi:nil": "true"
}
},
"reportLocale": {
"$": {
"xsi:nil": "true"
}
}
}
}
}
}
}
]
I've updated the answer base on your new JSON (thank you!). It looks like the problem is maybe that each property in the JSON is really an array.
I'd suggest if you don't want this behaviour, to have a look at the explicitArray options in the xml2js options object setting it to false.
e.g. :
explicitArray (default: true): Always put child nodes in an array if true; otherwise an array is created only if there is more than one.
This might simplify accessing properties!
let response = [
{
"Envelope": {
"$": {
"xmlns:soapenv": "http://schemas.xmlsoap.org/soap/envelope/",
"xmlns:xsd": "http://www.w3.org/2001/XMLSchema",
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance"
},
"Body": {
"runReportResponse": {
"$": {
"xmlns": "http://xmlns.oracle.com/oxp/service/PublicReportService"
},
"runReportReturn": {
"metaDataList": {
"$": {
"xsi:nil": "true"
}
},
"reportBytes": "MzAwMDAwMDA0Mzk5ODEwLERDT0cgQ29ycG9yYXRlIEJVDQozMDAwMDAwMDk0ODE4MzEsREVMRlRMQUJfVVNfQlVTSU5FU1NfVU5JVA0KMzAwMDAwMDAzMDYyNTI1LERFTEhJVEVDSF9VU19CVVNJTkVTU19VTklUDQozMDAwMDAwMDMwNjE1ODMsREVMTFMgVVMgQlUNCjMwMDAwMDAwMzE3OTE0NixERUxNRkcgVVMgQlUNCjMwMDAwMDAxMDI1NDA1NyxESEMgQ29ycG9yYXRlDQo=",
"reportContentType": "text/plain;charset=UTF-8",
"reportFileID": {
"$": {
"xsi:nil": "true"
}
},
"reportLocale": {
"$": {
"xsi:nil": "true"
}
}
}
}
}
}
}
];
console.log("Report bytes: ", response[0].Envelope.Body.runReportResponse.runReportReturn.reportBytes);
Related
The bug
Aliased attributes in union types resolve to null instead of their correct value when using schema stitching to combine two remote schemas.
The same query returns the correct result on the "non-stitched" schema when issued to the non-stitched schema at localhost:/4001/graphql
To Reproduce
Steps to reproduce the behavior:
checkout the github repo
follow the README.md steps:
npm i && npm run start
gateway on localhost:4444/graphql
remote-1 on localhost:4001/graphql
remote-2 on localhost:4002/graphql
go to localhost:4444/graphql (the stitched schema) and query
query {articles {title {
... on TitleOne {text}
... on TitleTwo {renamedText: text}
}}}
Expected behavior
result should contain correct values. E.g.
{
"data": {
"articles": [
{
"title": {
"text": "hello world"
}
},
{
"title": {
"renamedText": 1
}
},
{
"title": {
"renamedText": 2
}
},
{
"title": {
"text": "bye"
}
}
]
}
}
** Actual Behaviour **
result contains "null" for aliased fields
{
"data": {
"articles": [
{
"title": {
"text": "hello world"
}
},
{
"title": {
"renamedText": null
}
},
{
"title": {
"renamedText": null
}
},
{
"title": {
"text": "bye"
}
}
]
}
}
Environment:
OS: ubuntu 18.04
"#graphql-tools/load": "^7.5.8",
"#graphql-tools/schema": "^8.3.8",
"#graphql-tools/stitch": "^8.6.6",
"#graphql-tools/url-loader": "^7.9.11",
"#graphql-tools/wrap": "^8.4.13",
NodeJS: v14.19.1
Does anyone know how I can get this to return the correct values instead of "null"?
I have been trying to scan DynamoDB to check for particular value in a nested map attribute named deliverables. However using scan with filter expressions is resulting in an empty result.
import boto3
result = []
dynamo_client = boto3.client("dynamodb")
paginator = dynamo_client.get_paginator("scan")
operation_parameters = {
'FilterExpression': "#Deliverable= :deliverable",
'ExpressionAttributeNames': {
'#Deliverable': 'deliverables.fc986523-a666-478e-8303-2a1c3c1dc4ba'
},
'ExpressionAttributeValues': {
':deliverable': {
"M": {
"read": {
"BOOL": True
},
"upload": {
"BOOL": True
},
"write": {
"BOOL": True
}
}
}
}
}
for page in paginator.paginate(TableName="TableName", **operation_parameters):
result.append(page["Items"])
print(result)
The items in the dynamo db look like this:
[
[
{
"deliverables":{
"M":{
"7397d832-fefb-4ba2-97a1-0f6e73d611d9":{
"M":{
"read":{
"BOOL":true
},
"upload":{
"BOOL":true
},
"write":{
"BOOL":true
}
}
},
"fc986523-a666-478e-8303-2a1c3c1dc4ba":{
"M":{
"read":{
"BOOL":true
},
"upload":{
"BOOL":true
},
"write":{
"BOOL":true
}
}
}
}
},
"username":{
"S":"username1"
},
"deniedReferences":{
"L":[
]
}
},
{
"deliverables":{
"M":{
"7397d832-fefb-4ba2-97a1-0f6e73d611d9":{
"M":{
"read":{
"BOOL":true
},
"upload":{
"BOOL":false
},
"write":{
"BOOL":false
}
}
},
"fc986523-a666-478e-8303-2a1c3c1dc4ba":{
"M":{
"read":{
"BOOL":true
},
"upload":{
"BOOL":false
},
"write":{
"BOOL":false
}
}
}
}
},
"username":{
"S":"repositoryadmin"
},
"deniedReferences":{
"L":[
]
}
}
]
]
Please let me know if you can help me solve this issue.
The problem is the [dot] here: 'ExpressionAttributeNames': { '#Deliverable': 'deliverables.fc986523-a666-478e-8303-2a1c3c1dc4ba'}
Expressions docs: DynamoDB interprets a dot in an expression attribute name as a character within an attribute's name.
operation_parameters = {
"FilterExpression": "#D0.#D1=:deliverable", # the dot goes here!
"ExpressionAttributeNames": {
"#D0": "deliverables",
"#D1": "fc986523-a666-478e-8303-2a1c3c1dc4ba"
},
I want to search "search" parameter in headers, api_data, ip_address, tarih_2
where am i doing wrong? Help me please.
{
"$and":[
{
"$or":[
{
"headers":{
"$regex":".*94.54.232.96.*"
}
},
{
"api_data":{
"$regex":".*94.54.232.96.*"
}
},
{
"ip_address":{
"$regex":".*94.54.232.96.*"
}
},
{
"tarih_2":{
"$regex":".*94.54.232.96.*"
}
}
]
}
]
}
no problem with query. Thank you.
I am working on my first custom source plugin for gatsby, but I am stuck now..
Its working so far that I get the data I need create node, but not for all the data.
the response i get from the api looks like this
{
"section1": {
"date": "...",
"moreinformartion": "...",
},
"section2": [
{
"sub1": {
"information": "..."
}
},
{
"sub2": {
"information": "..."
}
},
{
"sub2": {
"information": "..."
}
}
]
}
But with all the tutorials out there, I was "only" able to get a node for every sub in section2
result.data.roster.forEach(data => {
const node = {
...data,
id: createNodeId(`KILL-setup-${data.character.name}`),
internal: {
type: 'KILLSetup',
contentDigest: createContentDigest(data)
}
};
actions.createNode(node);
});
How can I get 1 node, with all the data inside?
[ElasticSearch 5.5.1]
I dynamically build elasticsearch queries (in js/node.js using npm elasticsearch) and I've found that part of the pain of doing that is that I have to initialize the deeply nested objects before assignment (obviously). To simplify the coding of this, I created a helper function that auto-initializes all of the intermediate objects if they don't exist.
function esqAssign(esq, keyPath, value) { }
let esq = {};
esqAssign(esq, 'bool.must.range.timestamp.gte', <timestamp>)
==>
esq = { bool: { must: { range { timestamp: { gte: <timestamp> }}}}}}
This works great unless I have a field that uses the dot-expander syntax like:
esqAssign(esq, 'bool.filter.term.myfield.id', <id>)
=>
esq = { bool: { filter: { term: { myfield: { id: <id> }}}}}
which fails when I do the actual query. However, this works
esq = { bool: { filter: { term: { "myfield.id": <id> }}}}}
my index schema contains:
...
"myfield": {
"properties": {
"id": {
"type": "long"
},
}
}
To keep my code simple and not make the function signature esqAssign(esq, keyName, prop, value), I would like to avoid the dot-expander notation.
If I look at this from a curl perspective, I'm wondering why this works:
curl localdev:9200/myindex/mytype/_search -XPOST -d '{ "query": { "bool": { "filter": { "term": { "myfield.id": 1234 } } } } }'
and this doesn't:
curl localdev:9200/ myindex/mytype /_search -XPOST -d '{ "query": { "bool": { "filter": { "term": { "myfield": { "id": 1234 } } } } } }'
{
"error":{
"root_cause":[
{
"type":"parsing_exception",
"reason":"[term] query does not support [id]",
"line":1,
"col":69
}
],
"type":"parsing_exception",
"reason":"[term] query does not support [id]",
"line":1,
"col":69
},
"status":400
}
Any ideas on how to have ES accept { myfield: { id ...} instead of requiring { myfield.id: ...}?