Any help would be much appreciated. What I am trying to achieve is to request a record from Dynamics 365(cloud) to an on-premise system (exposed by mulesoft) I have decided to use Azure logic apps to do the integration and to use Liquid to do the mapping, however I am battling to flatten the array with liquid, I'm getting a JSON payload from the on-premise system which I need to transform readily to load into dynamics 365, what I am getting is something like the following:
{
"person": {
"firstname": " Fred",
"surname" : "Smith",
"age": 27,
"phoneno":"123456789",
"addresses": [
{
"address": {
"AddressLine1":"1 milky way",
"AddressLine2":"galaxy cresent",
"city": "tempest",
"state": "Idiho",
"postcode": "12345"
}
},
{
"address": {
"AddressLine1":"52 Saturn Drive",
"AddressLine2":"Wharfridge",
"city": "tempest",
"state": "Idiho",
"postcode": "12345"
}
}
]
}
}
and what I need is to flatten the array into the root node like this:
{
"person": {
"firstname": " Fred",
"surname" : "Smith",
"age": 27,
"phoneno":"123456789",
"addr1_AddressLine1":"1 milky way",
"addr1_AddressLine2":"galaxy cresent",
"addr1_city": "tempest",
"addr1_state": "Idiho",
"addr1_postcode": "12345",
"addr2_AddressLine1":"52 Saturn Drive",
"addr2_AddressLine2":"Wharfridge",
"addr2_city": "tempest",
"addr2_state": "Idiho",
"addr2_postcode": "12345"
}
}
If there any other solutions\ideas, i am all ears.
Thanks in advance for your help
Paul
So i found a solution or rather a work around, for some reason the liquid connector in logic apps does not support the "increment" tag, this was causing my issue. i was able to evaluate a property form the input json to decide where my fields would reside. but thanks for
Related
I'm trying to get Json-Server (v 0.12.1) working without the need for middleware or using it as a component - I already have something that works fine if I'm going to take the time to manually code all the endpoints. I'm attracted to the simplistic route config, and I believe I should be able to use it without requiring anything but a routes.json and db.json (letting me remove a lot of boilerplate express stuff).
My db.json:
"users": [
{
"userId": 1,
"favoriteColor": "red"
},
{
"userId": 2,
"favoriteColor": "blue"
},
{
"userId": 3,
"favoriteColor": "green"
}
]
My routes.json:
{
"/api/users": "/users",
"/api/users/:userId": "/users/:userId"
}
I want to be able to make a GET call to: http://localhost:3000/api/users/2 and get
{
"userId": 2,
"favoriteColor": "blue"
}
in return. However, I always just get {}.
Trying to use some suggestions from SO which either change the data structure (which I don't have control over) or using filters (which returns an array, not an object) are no-go for me.
Does anyone know why this seemingly-simply route is not working? I believe I'm following the custom route guidelines. I'm starting the server with json-server --watch ./api/db.json --routes ./api/routes.json, and hitting http://localhost:3000/api/users returns exactly what I expect, so I know the routes.json file and db.json file are both being picked up successfully.
Thank you!
I gotta working starting the server with:
json-server --watch db.json --routes routes.json
db.json
{
"users": [
{
"id": 1,
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian#codingthesmartway.com"
},
{
"id": 2,
"first_name": "Steve",
"last_name": "Palmer",
"email": "steve#codingthesmartway.com"
},
{
"id": 3,
"first_name": "Ann",
"last_name": "Smith",
"email": "ann#codingthesmartway.com"
}
]
}
routes.json
{
"/api/users": "/users",
"/api/users/:id": "/users/:id"
}
I'm using import.io and trying to figure out how to write a code that that uses multiple inputs to run a connector query. I've never used JSON before but essentially what I'm trying to do is to expand this existing query:
{
"input": {
"name": "Marin Academy",
"city": "San Rafael"
},
}
To include multiple names. So that when I run the query, IO automatically searches a list of organizations. What would be the correct syntax to achieve this?
I tried
{
"input": {
"name": "Marin Academy",
"city": "San Rafael"
},
{
"name": "Mt. Hood Community College",
"city": "Gresham"
}
}
But it gives me a syntax error.
Thanks!
In case of an an array, please use square brackets before the beginning and after the end of curly brackets like...
{
"input": [
{
"name": "Marin Academy",
"city": "San Rafael"
},
{
"name": "Mt. Hood Community College",
"city": "Gresham"
}
]
}
This will solve the JSON sytax error at least.
I am working with some data and often the data is nested and i am required to perform some CRUD operations based on the structure of the data i have. For instance i have this json structure
{
"_id": "KnNLkJEhrDsvWedLu",
"createdAt": {
"$date": "2016-10-13T11:24:13.843Z"
},
"services": {
"password": {
"bcrypt": "$2a$30$1/cniPwPNCuwZ/MQDPQkLej..cAATkoGX.qD1TS4iHgf/pwZYE.j."
},
"email": {
"verificationTokens": [
{
"token": "qxe_T9IS7jW7gntpK0Q7UQ35RJ9jO9m2lclnokO3z87",
"address": "drwho#gmail.com",
"when": {
"$date": "2016-10-13T11:24:14.428Z"
}
}
]
},
"resume": {
"loginTokens": []
}
},
"username": "doctorwho",
"emails": [
{
"address": "drwho#gmail.com",
"verified": false
}
],
"persodata": {
"lastlogin": {
"$date": "2016-10-13T11:29:36.816Z"
},
"fname": "Doctor",
"lname": "Who",
"mobile": "+4480000000",
"identity": "1",
"email": "drwho#gmail.com",
"gender": null
}
}
I have several data sets with such complex structure. I need to read the data, edit and also delete. Before i get to iteration, i was wondering how i can read the data without iteration then iterate when i absolutely have to.
What are the rules i should keep in mind when reading such complex json structures to enable me read any complex structure i come across?.
I am currently using javascript but i am looking for rules that apply in other languages as well.
Parsing Json in JavaScript should be easy. http://www.json.org/js.html.
"Since JSON is a proper subset of JavaScript, the compiler will correctly parse the text and produce an object structure". Just follow the examples on that page.
If you want to use another language, in Java you could use Jackson or Gson to map those json strings to objects. Then using them becomes easy. Both libraries are annotation based, and wouldn't be difficult to implement.
I want to write a description document for my JSON files. I used to write it for database. It has ER Diagram and Data Dictionary. But when it comes to JSON file, are there any diagrams that can be used to describe JSON file that can be read easily?
Try out http://jsonviewer.stack.hu/. For a json string like this,
{
"address": {
"streetAddress": "21 2nd Street",
"city": "New York"
},
"phoneNumber": [
{
"type": "home",
"number": "212 555-1234"
}
]
}
It produces an output like,
How to use jsp to get json resulting in folowing format ?
{
"firstName": "John",
"lastName": "Smith",
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": 10021
},
"phoneNumbers": [
"212 732-1234",
"646 123-4567"
]
}
You can use different libraries to convert from diferent java objects to JSON
For example the library json-simple http://code.google.com/p/json-simple/
In the json-simple page you can see some examples of encoding,decoding, and JSP & AJAX with these library.
Structure a Java object in a similar fashion and then use a serialization mechanism
such as json-simple or xstream with Json Driver
for instance
new XStream(new JettisonMappedXmlDriver());
xstream.toXML(object);
Got it.
Create JSONObject.
Create JSONArray.
Merge.
Thanks guy. Appreciate.