parsing xml to json through fast-xml-parser changes the string value - fast-xml-parser

i am parsing a xml having this attribute : 42303933365137544b36 when converting to json the value of sku changes to : "sku" : "42303933365446540000",
i am using fast-xml-parser in node
Kindy suggest what is the issue and how can we resovle this ..

Related

How do i get only the Json keys as a output from ADF lookup activity

This is my json which read via a lookup activity
{
"key1" : { "id" = "100" },
"key2" : "XYZ",
"key3" : [1,2,3]
}
I need a activity that gives me all the keys alone from above json
Lookup.output.firstrow.key2 gives me the string XYZ
What expression i can use to get all the keys alone
I really looking for some expression like Lookup.output.firstrow.getKeys() which returns array of keys such as
["key1", "key2", "key3"]
How do i get only the Json keys as a output from ADF lookup activity
There is no such direct way to achieve this you have to do it by setting the variables and string manipulation.
Follow below procedure:
I took json file in look up and its output is as follow:
To get all keys from above Json first I took set variable activity and created a demo string variable with value.
#substring(string(activity('Lookup1').output.value),2,sub(length(string(activity('Lookup1').output.value)),4))
here we are converting lookup output to string and removing braces from start and end.
Then I took another set variable activity and created a demo2 array variable with value.
#split(substring(string(split(variables('demo'),':')),2,sub(length(string(split(variables('demo'),':'))),4)),',')
Here we are splitting the string with : and ,
Then I created an array with default range of even numbers of values 0,2,4,6 etc.
Then Passed it to ForEach activity
Then Inside For Each activity I took append variable activity and gave value as
#variables('demo2')[item()]
Output:
Note: if your values contain : or , the above expression will also split those values. and if we split the values with : then I will split the string with : only and rest thing it will consider as single value. In below image the highlighted value it is taking as single value.

Mulesoft: How can I apply the {header:false} option when getting an Excel file from server

In DataWeave when using the readUrl() function, I can utilize the {"header":false} option as shown below to give the column as the key and cell as the value in a JSON object:
var myInput = readUrl("classpath://examples/Test.xlsx", "application/xlsx", {"header":false})
JSON
{
A: "A1",
B: "B1",
C: "",
D: "",
E: "E1"
}
I'm using a REST API call to Salesforce to retrieve an Excel file. Is there a way to apply a similar option of {"header":false} to be able to provide the content of the Excel file in similar way as JSON above?
Use this mule docs references to see supported read properties.
https://docs.mulesoft.com/dataweave/2.4/dataweave-formats-excel
You can use a transform message and use the same value as shown below
%dw 2.0
input payload application/xlsx header=false
output application/json
---
You should set the correct data format and properties in the operation or source where the payload is created with the outputMimeType attribute. This is explained in the documentation. In this case the operation is the <http:request>.
Example:
<http:request ... outputMimeType="application/csv; header=false">

How to get File Upload field properties from Microsoft Form in Power Automate?

Desired Behaviour
I am trying to get the file properties of a file uploaded via a Microsoft Form in Power Automate.
Research
I've tried numerous variations of suggestions from sources such as:
How to get data from JSON objects using expressions in Power Automate (video)
Working with files from the Forms "File Upload" question type
Reference guide to using functions in expressions for Azure Logic Apps and Power Automate
I am a fairly experienced developer and I am familiar with variable types (String, Array, Object etc) and how to reference items in an object with dot or bracket notation and accessing array items by index.
I'm also familiar with:
JSON.parse()
The JSON.parse() method parses a JSON string, constructing the JavaScript value or object described by the string.
JSON.stringify()
The JSON.stringify() method converts a JavaScript object or value to a JSON string
And have read about Power Automate's Parse JSON action
To reference or access properties in JavaScript Object Notation (JSON) content, you can create user-friendly fields or tokens for those properties by using the Parse JSON action. That way, you can select those properties from the dynamic content list when you specify inputs for your logic app. For this action, you can either provide a JSON schema or generate a JSON schema from your sample JSON content or payload
But I am still having a lot of difficulty getting the values I need.
What I've Tried
01) Use Parse JSON to access properties of the Reponse body:
02) Run the flow and look at the Raw Outputs of Parse JSON:
{
"body": {
"responder": "me#domain.com",
"submitDate": "7/5/2021 7:03:26 AM",
"letters-and-numbers-here-1": "some text here",
"letters-and-numbers-here-2": "[{\"name\":\"File 01 Name.docx\",\"link\":\"https://tenant.sharepoint.com/sites/MySiteName/_layouts/15/Doc.aspx?sourcedoc=%7Bletters-and-numbers%7D&file=File%2001%20Name%20_Uploader%20Name.docx&action=default&mobileredirect=true\",\"id\":\"id-is-here\",\"type\":null,\"size\":20411,\"referenceId\":\"reference-id-is-here\",\"driveId\":\"drive-id-is-here\",\"status\":1,\"uploadSessionUrl\":null}]",
"letters-and-numbers-here-3": "[{\"name\":\"File 02 Name.docx\",\"link\":\"https://tenant.sharepoint.com/sites/MySiteName/_layouts/15/Doc.aspx?sourcedoc=%7Bletters-and-numbers%7D&file=File%2002%20Name%20_Uploader%20Name.docx&action=default&mobileredirect=true\",\"id\":\"id-is-here\",\"type\":null,\"size\":20411,\"referenceId\":\"reference-id-is-here\",\"driveId\":\"drive-id-is-here\",\"status\":1,\"uploadSessionUrl\":null}]",
"letters-and-numbers-here-4": "some other text here"
}
}
03. Try and get the name value of the first File Upload field.
I had assumed that the first Parse JSON would have recursively set all values as JSON Objects, however it looks like the value of the File Upload field is still a string. So I figure I have to do another Parse JSON action on the File Upload field.
Content:
body('Parse_JSON')?['letters-and-numbers-here-2']
Sample JSON Payload:
{
"letters-and-numbers-here-2": "[{\"name\":\"File 01 Name.docx\",\"link\":\"https://tenant.sharepoint.com/sites/MySiteName/_layouts/15/Doc.aspx?sourcedoc=%7Bletters-and-numbers%7D&file=File%2001%20Name%20_Uploader%20Name.docx&action=default&mobileredirect=true\",\"id\":\"id-is-here\",\"type\":null,\"size\":20411,\"referenceId\":\"reference-id-is-here\",\"driveId\":\"drive-id-is-here\",\"status\":1,\"uploadSessionUrl\":null}]"
}
Which produces the Error:
[
{
"message": "Invalid type. Expected Object but got Array.",
"lineNumber": 0,
"linePosition": 0,
"path": "",
"schemaId": "#",
"errorType": "type",
"childErrors": []
}
]
So I tried to target the first Object within the File Upload field Array, and I try the following values as the Content of Parse JSON 2:
body('Parse_JSON')?['letters-and-numbers-here-2']?[0]
body('Parse_JSON')['letters-and-numbers-here-2'][0]
Both produce the error:
Unable to process template language expressions in action 'Parse_JSON_2' inputs at line '1' and column '9206': 'The template language expression 'body('Parse_JSON')['letters-and-numbers-here-2'][0]' cannot be evaluated because property '0' cannot be selected. Property selection is not supported on values of type 'String'. Please see https://aka.ms/logicexpressions for usage details.'
Question
How do I access the File Upload field properties?
For reference, the Microsoft Form has 4 fields of type:
Text
File Upload (limited to 1 file only)
File Upload (limited to 1 file only)
Choice
The connectors used are:
When a new response is submitted
Get response details
The body returned by Get response details, in Raw outputs, is:
"body": {
"responder": "me#domain.com",
"submitDate": "7/5/2021 3:17:56 AM",
"lots-of-letters-and-numbers-1": "text string here",
"lots-of-letters-and-numbers-2": [{.....}],
"lots-of-letters-and-numbers-3": [{.....}],
"lots-of-letters-and-numbers-4": "text string here"
}
I tried a different approach, without the Parse JSON action, and could access the file name:
The expression values were:
`Compose` > `Inputs`: json(body('Get_response_details')?['lots-of-letters-and-numbers-2'])
`Initialize Variable` > `Value`: outputs('Compose')[0]['name']
Or, even simpler, just using Compose:
Or Initialize variable:
Using this expression with json() and body():
json(body('Get_response_details')?['lots-of-letters-and-numbers-2'])[0]['name']
I'm not sure if this is the best approach or if it comes with any 'gotchas'.

Converting stream to string in node.js

I am reading a file which comes in as an attachment like follows
let content = fs.readFileSync(attachmentNames[index], {encoding: 'utf8'});
When I inspect content, it looks ok, I see file contents but when I try to assign it to some other variable
attachmentXML = builder.create('ATTACHMENT','','',{headless:true})
.ele('FILECONTENT',content).up()
I get the following error
Error: Invalid character in string: PK
There are a couple of rectangular boxes (special characters) after PK in the above message which are not getting displayed.
builder here refers to an instance of the xmlbuilder https://www.npmjs.com/package/xmlbuilder node module.
I fixed this by enclosing the string inside a JS escape() method

Parsing JSON array in Azure Logic App from base64 encoded string to use in For_each

I am trying to iterate through a JSON array which has been encoded to a string for the purpose of storing on a queue. However, I receive the following error message:
{"code":"ExpressionEvaluationFailed","message":"The execution of
template action 'For_each' failed: The result '[{\"Foo\":\"Bar\"}]' of
the evaluation of 'foreach' action expression
'#{json(decodeBase64(triggerBody()['ContentData']))}' is not a valid
array."}
The following is the string being parsed:
[{"Foo":"Bar"}]
I have no problems parsing a JSON string when it is not in an array, for example:
{"Foo":"Bar"}
This parses just fine when I am not using a For_each.
How do I get the logic app to read this as an array?
The issue here is that you are using string interpolation (where expressions are wrapped in #{ ... }) that evaluates to a string representation of the array. Hence evaluation of the 'foreach' expression fails.
You want the expression to be
#json(decodeBase64(triggerBody()['ContentData']))
json(decodeBase64(body('HTTP')?['$Content']))
enter image description here

Resources