I'm totally new on transforming JSON to CSV in Mulesoft. Currently i need to work on to transform a nested JSON into CSV which my CSV should look like this and my JSON will be like
{
"Invoice": [
{
"Invoice Number*": "",
"Supplier Name": "",
"Supplier Number": "",
"Status": "",
"Invoice Date*": ""
}
],
"Invoice Line": [
{
"Invoice Number*": "",
"Supplier Name": "",
"Supplier Number": "",
"Line Number": "",
"Description*": "",
"Supplier Part Number": "",
"Auxiliary Part Number": "",
"Price*": "",
"Quantity": "",
"Bulk Price": "",
"Bulk Price Qty": ""
}
],
"Invoice Tax Line": [
{
"Invoice Number*": "",
"Invoice Line Number": "",
"Invoice Charge Number": "",
"Line Number": "",
"Tax Amount": "",
"Tax Rate": "",
"Tax Code": "",
"Tax Rate Type": ""
}
]
}
What i know about CSV is there will be only one header. What is the best way for me to map this complex JSON into CSV which will shows different header?
You can do something like this:
%dw 2.0
output application/csv header=false
---
flatten (
[
{"Invoice Number":"Invoice Number",
"Supplier Name": "Supplier Name",
"Supplier Number" :"Supplier Number",
"Status" : "Status",
"Invoice Date*" : "Invoice Date*"
},
{
"Invoice Number":"Invoice Number*",
"Supplier Name":"Supplier Name",
"Supplier Number":"Supplier Number",
"Status":"Status",
"Invoice Date*":"Invoice Date*"
},
payload.Invoice map {
"Invoice Number":$."Invoice Number*",
"Supplier Name":$."Supplier Name",
"Supplier Number":$."Supplier Number",
"Status":$.Status,
"Invoice Date*":$."Invoice Date*"
},
payload."Invoice Line" map {
"Invoice Number": $."Invoice Number*",
"Supplier Name":$."Supplier Name",
...
}
,
payload."Invoice Tax Line" map {
"Invoice Number":$."Invoice Number*",
...
}
]
)
Related
Getting response code 00027 from payfort using Merchant page 2.0. This is happening when the card details are saved on the frontend.
{
"amount": "9900",
"response_code": "00027",
"signature": "",
"merchant_identifier": "",
"access_code": "",
"customer_ip": "127.0.0.1",
"language": "en",
"command": "PURCHASE",
"merchant_extra": "3",
"response_message": "Invalid extra parameters : card_security_code",
"merchant_reference": "",
"customer_email": "sufyan.khot#domain.com",
"merchant_extra1": "domain.com/en",
"merchant_extra2": "domain.com",
"currency": "AED",
"customer_name": "test test",
"status": "00"
}
I am trying to validate the data being passed with an array of objects in a JSON request. I used express-validator wildcards as specified in the documentation, but the error messages are returned irrespective of whether the properties of the objects are empty or not. I have checked various solutions online in an attempt to debug the issue, all to no avail. I will appreciate if anyone can point out what I am doing wrongly and suggest a correct solution, thanks.
The Validation
body("*.product", "Invalid or Empty Product Details").trim().notEmpty(),
body("*.price", "Invalid or Empty Product Price").trim().notEmpty(),
body("*.customer", "Invalid or Empty Customer Details")
.trim()
.notEmpty(),
body("*.seller", "Invalid or Empty Seller Details").trim().notEmpty(),
body("*.haulageOptions", "Invalid or Empty Haulage Options").trim().notEmpty()
The JSON Request
{
"order": [
{
"product": {
"commodity": "",
"quantity": ""
},
"price": {
"orderPrice": "",
"deliveryPrice": "",
"totalPrice": ""
},
"customer": {
"name": "",
"email": "",
"location": {
"state": "",
"localGovernment": "",
"town": "",
"address": ""
}
},
"seller": {
"name": "",
"phone": [
""
],
"email": ""
},
"haulageOptions": {
"firstOrder": "",
"secondOrder": "",
"thirdOrder": ""
}
}
]
}
I figured it out
The Validation
check("order.*.product.commodity", "Empty Product Commodity").trim().notEmpty(),
check("order.*.product.quantity", "Empty Product Quantity").trim().notEmpty(),
check("order.*.price.orderPrice", "Empty Product Order Price").trim().notEmpty(),
check("order.*.price.deliveryPrice", "Empty Product Delivery Price").trim().notEmpty(),
check("order.*.price.totalPrice", "Empty Product Total Price").trim().notEmpty(),
check("order.*.customer.name", "Empty Customer Name").trim().notEmpty(),
check("order.*.customer.email", "Empty Customer Email").trim().notEmpty(),
check("order.*.customer.location.state", "Empty Customer Location (State)").trim().notEmpty(),
check("order.*.customer.location.localGovernment", "Empty Customer Location (Local Government)").trim().notEmpty(),
check("order.*.customer.location.town", "Empty Customer Location (Town)").trim().notEmpty(),
check("order.*.customer.location.address", "Empty Customer Location (Address)").trim().notEmpty(),
check("order.*.seller.name", "Empty Seller Name").trim().notEmpty(),
check("order.*.seller.phone", "Empty Seller Phone Number").trim().notEmpty(),
check("order.*.seller.email", "Empty Seller Email Address").trim().notEmpty(),
check("order.*.haulageOptions.firstOrder", "Empty Haulage Options").trim().notEmpty(),
I am trying to map an array payload into CSV in Dataweave and not able to achieve the result.
The csv will not need header, the content in the array will print in column by column. I'm facing problem to make the mapping through the nested array.
Input payload
[
{
"Invoice": {
"Invoice Number*": "Test",
"Supplier Number": "1201",
"Submit For Approval?": "Yes",
"Invoice Date*": "20190828",
"Line Level Taxation*": "Yes",
"Payment Date": "00/00/0000",
"Original invoice number": "",
"Original invoice date": ""
},
"Invoice Line": [
{
"Invoice Number*": "Test1",
"Line Number": "1",
"Description*": "Test1",
"Price*": "500",
"Quantity": null,
"Unit of Measure*": null,
"PO Number": "001",
"PO Line Number": "1"
},
{
"Invoice Number*": "Test2",
"Line Number": "2",
"Description*": "Test2",
"Price*": "500",
"Quantity": null,
"Unit of Measure*": null,
"PO Number": "001",
"PO Line Number": "2"
}
],
"Invoice Tax Line": [
{
"Tax Amount": "500",
"Invoice Line Number": "1",
"Line Number": "1"
},
{
"Tax Amount": "50",
"Invoice Line Number": "2",
"Line Number": "2"
}
]
}
]
Expected Output
column_0, column_1, column_2 ... //no header
"Invoice Number*","Supplier Number","Submit For Approval?"... //Invoice
"Invoice Number*","Line Number*"... //InvoiceLine[0]
"Tax Amount","Invoice Line Number","Line Number"... //Tax Line[0]
"Invoice Number*","Line Number*"... //InvoiceLine[1]
"Tax Amount","Invoice Line Number","Line Number"... //Tax Line[1]
How can i write the dataweave mapping to archive the result like above?
This is the solution I found for your use case. Basically there are two functions to that dispatches on the right method according to the type. And then you also want to use zip function to mix one "Invoice Line" with one "Invoice Tax Line" so they are mixed correctly.
%dw 2.0
output application/csv headers=false
import * from dw::core::Objects
fun collectKeyNames(obj: {}): Array<{}> =
[
obj
]
fun collectKeyNames(arr: Array): Array<{}> =
arr flatMap ((obj, index) -> collectKeyNames(obj))
---
payload flatMap ((item, index) ->
collectKeyNames(item.Invoice) ++
(collectKeyNames(item."Invoice Line" zip item."Invoice Tax Line"))
)
How can I reduce warning of "Missing product ID (optional)" on "application/ld+json" script in google search console?
Below My sample JSON-LD code
<script type="application/ld+json">
{
"#context": "http://schema.org/",
"#type": "Product",
"name": "done product Name here",
"url": "done product url here",
"image": [
"done image url here"
],
"description": "done description here",
"sku": "H100000001",
"productID" : "9876543210", // Added like this type behaviour
"brand": {
"#type": "Thing",
"name": "cosmetics"
},
"offers": [{
"#type" : "Offer",
"sku": "H100000002",
"availability" : "http://schema.org/InStock",
"price" : "26.0",
"priceCurrency" : "USD",
"url" : "product url"
},
{
"#type" : "Offer",
"sku": "H100000003",
"availability" : "http://schema.org/InStock",
"price" : "26.0",
"priceCurrency" : "USD",
"url" : "product url"
},
{
"#type" : "Offer",
"sku": "H099020004",
"availability" : "http://schema.org/InStock",
"price" : "26.0",
"priceCurrency" : "USD",
"url" : "product url"
}]
}
</script>
I have tried different variables of product id below
1. "productID" : "9876543210",
2. "productID" : "isbn:9876543210",
3. "product-id" : "isbn:9876543210",
4. "product-id" : "9876543210",
but error still getting.
Can anyone help how can I solve the issue of Missing product ID (optional)" on Google Search Console?
Which behavior is correct for set product id in ld+json?
The message from Google is not very clear... what it's looking for is one of product IDs from https://schema.org/Product (gtin13, etc.). I was getting the same error after adding ProductID, but once I replaced ProductID with the gtinxxx values, the warning went away.
When I try to create a new account using the API I am getting this error:
{ "error": "internal_server_error", "error_description": "No site id
was found for region: None", "reference_id":
"e2ff6d67-119e-4b04-9325-512047e5baf5" }
My payload is:
{ "accounts": [ {
"address": {
"street_address": "santendar",
"locality": "santendar",
"region": "spanish area",
"country": "ESP",
"postal_code": "34567",
"phone": "12345"
},
"admin_user": {
"email_address": "abhistar002#gmail.com",
"first_name": "test",
"last_name": "team",
"job_title": "somejob"
},
"name": "testAccount",
"plan_id": "**********************",
"website": "example.com",
"reseller_id": "***********",
"customer_id": "************",
"paid_seats": "2"
} ] }
Which worked before. I have created many accounts using this API structure.
Any suggestions how to resolve this issue?
IF you look at this https://developers.docusign.com/esign-rest-api/reference/Accounts/Accounts/create you'll see that the Address part of your call is a bit different and should look like this:
"address": {
"street1": "sample string 1",
"street2": "sample string 2",
"city": "sample string 3",
"state": "sample string 4",
"zip": "sample string 5",
"phone": "sample string 6",
"fax": "sample string 7",
"country": "sample string 8"
}