Map file in the Integration for the LogicApp in Azure - json

Have the following XML as a result of the HTTP GET function from the B2B supplier.
<Invoices xmlns="http://gateway.com/schemas/Invoices" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://gateway..com/schemas/Invoices Invoices.xsd">
<DocumentInfo>
<DocType>INVOICES</DocType>
<DocVersion>2.0</DocVersion>
</DocumentInfo>
<Header>
<StartDate>2018-12-01T00:00:00+01:00</StartDate>
<EndDate>2019-01-03T00:00:00+01:00</EndDate>
</Header>
<Documents>
<Invoice InvoiceId="RP82807" InvoiceDate="2019-01-02T00:00:00+01:00" DocumentType="IN" RefDocId="FT34532" RefDocType="ORDER" SystemId="10" HasPDFImage="0" />
<Invoice InvoiceId="T609881" InvoiceDate="2018-12-31T00:00:00+01:00" DocumentType="IN" RefDocId="FT39339" RefDocType="ORDER" SystemId="0" HasPDFImage="0" />
</Documents>
</Invoices>
Based on this article I've created the liquid map file to get the list of InvoiceIds:
{
"Invoice": "{{content.Documents.Invoice}}"
}
When using it in the LogicApp in the XML->Json converter, got the following result:
{
"Invoice": ""
}
I have also tried this as a liquid file:
{
"Invoice": "{{content.Invoices.Documents}}"
}
and this:
{
"Invoice": "{{content.Invoices.Documents.Invoice}}"
}
with the same result.
Can you give me a tip what I do wrong?

I tried to transfer part of your xml file to json with this map:
{
"DocType":"{{content.DocumentInfo.DocType}}",
"Invoice":"{{content.Documents.Invoice}}"
}
And get the output:
{
"DocType": "INVOICES",
"Invoice": ""
}
So this means I can get the DocType but can't get Invoice properties, so I think maybe the Liquid map doesn't support the XML format. Maybe you could change it to like this:
<Invoice>
<InvoiceId>T609881</InvoiceId>
<InvoiceDate>2018-12-31T00:00:00+01:00</InvoiceDate>
<DocumentType>IN</DocumentType>
<RefDocId>FT39339</RefDocId>
</Invoice>
This will work, or you could go to Liquid reference to check is there any methods to match the properties.
Note:what you want for now,binding to Xml Attributes is not currently supported.You could refer to this answer.
If you still have other questions, please let me know.
UPDATE:You still could do it with logic app. For example I used a FTP connector to get xml file content then create a json with "json(xml(body('Get_file_content')))" expression.
And this is the result.

Related

How to save a JSON-object and use it in another request?

i'm currently trying to set up some JMeter testplans. I am pretty new to this (started a week ago) and don't have much programming experience either, so i hope you could help me in this case.
I already set up some http requests and have some simple JSON Extractor post processors to save some of the variables and use them with the "${variable}" notation.
But now i need to save and modify an object from a response to use that in the next http request.
My respose is a extremely big JSON object and the part im interested in looks something like this:
{
"payload": {
"workspace": {
"resultInstance": [
[{"part": "1"...}],
[{"part": "2"...}],
...
[{"part": "20"...}]
]
}
}
}
Note that for whatever reason these objects {"part":"1"...} are inside a nested array. And they are also pretty big.
I would like to safe those objects in a variable to use them in my next http request which should looks like this:
{
"instanceChange": {
"functionChecks": [
{"part": "1"...},
{"part": "2"...},
...
{"part": "20"...}
]
}
}
So what im really trying to find is a way to save all of the possible objects inside the nested array "resultInstance" and put them inside the non nested array "functionChecks".
I already looked inside the JMeter documentation but because of my poor programming background i cant find a way to realize this.
I think i need something like the JSR223 PostProcessor and "simply go through the resultInstance-array and use smth. like an getObject() on these", but i cant figure out the code i need and if its even possible to safe objects in variables in Jmeter.
Im pretty thankful for every bit of help or advice :).
Thanks in advance,
aiksn
Add JSR223 PostProcessor as a child of the request which returns the JSON response
Put the following code into "Script" area:
def response = new groovy.json.JsonSlurper().parse(prev.getResponseData())
def request = ['instanceChange': ['functionChecks': response.payload.workspace.resultInstance]]
vars.put('request', new groovy.json.JsonBuilder(request).toPrettyString())
That's it, you should be able to refer the generated request body as ${request} where required
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It
let response ={
"payload": {
"workspace": {
"resultInstance": [
[{"part": "1"...}],
[{"part": "2"...}],
...
[{"part": "20"...}]
]
}
}
};
let requestObj={
"instanceChange": {
"functionChecks": [
]
}
};
response.payload.workspace.resultInstance.forEach(myFunction);
myFunction(item, index) {
requestObj.instance.functionsCheck.push(item[0]);
}

Elasticsearch search templates

I tried using ES's search template to do a conditional clause as specified here. I'm sending my request to the /[my_index]/_search/template endpoint. The request fails because of JSON parsing issues, which makes sense because after adding the conditional clause the payload is no longer a valid JSON. How than am I supposed to use the search templates? Is there a designated endpoint for non-JSON templates?
When using conditional clauses,the template will not be a valid JSON because it will include the section markers {{# like this }}.For this reason, the template should either be stored in a file or, when used via the REST API, should be written as a string.
Method 1 : tempalte stored in a file
Save the query part of the template in config/scripts
ES installation>Config>scripts
test_template.mustache
{
"query":{ whatever query }
}
you can use the saved template by this method through sense
GET /_search/template
{
"template": "test_template",
"params": {
whatever params
}
}
Method 2: template written as a string
convert the template to string form and use via rest api
POST /_search/template/test_template
{
"template": "{\"query\":{ whatever query; remember to escape quotes}}"
}
To search using this template,
GET /_search/template
{
"template": {
"id": "test_template"
},
"params": {
whatever params
}
}
Reference: https://www.elastic.co/guide/en/elasticsearch/reference/1.7/search-template.html#_conditional_clauses
You need to escape the template in wrapping string.
From the same link you referenced:
As written above, this template is not valid JSON because it includes
the section markers like {{#line_no}}. For this reason, the template
should either be stored in a file (see the section called
“Pre-registered templateedit”) or, when used via the REST API, should
be written as a string:
"template":
"{\"query\":{\"filtered\":{\"query\":{\"match\":{\"line\":\"{{text}}\"}},\"filter\":{{{#line_no}}\"range\":{\"line_no\":{{{#start}}\"gte\":\"{{start}}\"{{#end}},{{/end}}{{/start}}{{#end}}\"lte\":\"{{end}}\"{{/end}}}}{{/line_no}}}}}}"

Uson jsTree with custom JSON structure

I've been searching for ways to do this, but I'm missing something.
I have a custom JSON object, which can basically have any structure, and I want to use this with jsTree. I've found a corresponding plugin here, that claims to have a _parse_json function to transform a custom JSON object to the format that jsTree requires, but for the life of me I can't figure out how to call that plugin. It seems to be included in the version of jsTree that I'm using (1.0rc3).
There is a usage of UIMTreeProcessor I've found, that consists of parsing the XML and calling jsTree like so:
$.jstree._themes = "Content/jstreethemes/";
this.treeEl.jstree({
"json_data" : {
"data":data,
"progressive_render":"true"
},
"plugins" : [ "themes", "ui", "json_data" ],
"core": { "animation": 0 }
});
Now, instead of UIMTreeProcessor parsing the XML and populating data, I want to call $.json_data._parse_json(), but I keep getting errors that this function doesn't exist.
Can anyone show me an example? Thank you kindly.

d3js forced directed cannot read from json

I have a simple json file which is :
{
"nodes":[
{"name":"Moe","group":1},
{"name":"Madih1","group":1},
{"name":"Madih2","group":1},
{"name":"Nora","group":1},
{"name":"Myna","group":1}
],
"links":[
{"source":35,"target":44,"value":1},
{"source":44,"target":35,"value":1},
{"source":45,"target":35,"value":1},
{"source":45,"target":44,"value":1},
{"source":35,"target":49,"value":1},
{"source":49,"target":35,"value":1}
]
}
when I save it use exactly the html code as shown in http://bl.ocks.org/4062045#index.html and address the above json, nothing appears on the cancas.
I appreciate it if you help me with this one as I am not very familiar with it. Moreover, it would be great if I know the minimum code required for drawing a graph like this using json.
Best,
The number of "source" and "target" refer to the index of the item in nodes array.
So you can change your json to following:
{
"nodes":[
{"name":"Moe","group":1},
{"name":"Madih1","group":1},
{"name":"Madih2","group":1},
{"name":"Nora","group":1},
{"name":"Myna","group":1}
],
"links":[
{"source":0,"target":1,"value":1},
{"source":1,"target":2,"value":1},
{"source":2,"target":3,"value":1},
{"source":3,"target":4,"value":1},
]
}
Then you can just copy the codes from http://bl.ocks.org/4062045#index.html example as the minimum code.
Remenber to change the json file to your own json file.
d3.json("path/to/your/json", function(error, graph) {
//codes
});

Solr Mulivalued Problem

Consider The following is the json response i'm getting from the solr if i use multivalued = true for the fields.
{
"id":["1","2","3"],
"TS":["2010-06-28 00:00:00.0","2010-06-28 00:00:00.0","2010-06-28 00:00:00.0"],
"Type":["VIDEO","IMAGE","VIDEO"]
}
but i need the response like this
{
"0":["1","2010-06-28 00:00:00.0","VIDEO"],
"1":["2","2010-06-28 00:00:00.0","IMAGE"],
"2":["3","2010-06-28 00:00:00.0","VIDEO"]
}
How can i get this.Any help would be appreciated. Thanks in advance.
**Update :**
Actually at the first level its not a problem. When we are going
more than one level then only the
problem arises. right now i'm putting
the entire response here to make it
clear.
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"facet":"true",
"indent":"on",
"start":"0",
"q":"laptop",
"wt":["json",
"json"],
"rows":"200"}},
"response":{"numFound":1,"start":0,"docs":[
{
"createdBy":"0",
"id":194,
"status":"ACTIVE",
"text":"Can i buy Sony laptop?",
"ansTS":["2010-07-01 00:00:00.0","2010-08-06 15:11:55.0","2010-08-11 15:28:13.0","2010-08-11 15:30:49.0","2010-08-12 01:45:48.0","2010-08-12 01:46:18.0"],
"mediaType":["VIDEO","VIDEO","VIDEO"],
"ansId":["59","76","77","78","80","81"],
"mediaId":[24,25,26],
]},
]
},
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"catName":[]},
"facet_dates":{}}}
look at the mediaId , mediatype ,ansTS arrays. Its one to many relationship.But they are grouped by column names.Thanks in advance.
You mentioned that you will consume this JSON from a browser. So you can use jQuery or any other javascript library to convert the raw Solr JSON response into the structure that you need.
If the first snippet is the actual solr response you're getting, then chances are you have a bug in your feeder (connector/crawler/etc). It looks like you only have one indexed document (that matches your query), which has all the values that you expect from 3 documents.
Assuming you have 3 documents, analogous with your expected output, then the actual solr wt=json result would contain:
[{
"id":"1",
"TS":"2010-06-28 00:00:00.0",
"Type":"VIDEO"
},
{
"id":"2",
"TS":"2010-06-28 00:00:00.0",
"Type":"IMAGE"
},
{
"id":"3",
"TS":"2010-06-28 00:00:00.0",
"Type":"VIDEO"
}]
If this assumption is correct, then I would suggest looking over your indexing logic.
This output is produced by Solr's JSONResponseWriter. Its output can't be altered via configuration. But what you can do is create your own version of JSONResponseWriter to produce your desired output. You can registered your new ResponseWriter by adding a queryResponseWriter tag in solrconfig.xml.