I'm trying to parse a JSON from a rest service. This service does not put the data into the format that I think ItemFileReadStore wants, but I cannot change it. Everything I have found in the dojo library for reading JSON data requires an identifier, which my data does not have. This is the JSON data:
{"ChannelReadResponse":[
{"Event": {"#entityOrigin":"System","#entityId":"0x080e00000136ad8986520af104608052","Name":"Untitled","SymbolCode":"OHVPEV---------","TimeObserved":"2012-04-13T21:09:49.207Z","CreatedUser":"Helpdesk","ModifiedUser":"Helpdesk","CreatedTime":"2012-04-13T21:09:49.207Z","ModifiedTime":"2012-04-17T15:51:12.496Z"},
{"#entityOrigin":"System","#entityId":"0x080e00000136bb54ec770af104608028","Name":"My Event","SymbolCode":"OHVPE----------","Severity":"SIGACT","Outcome":"Effective","TimeObserved":"2012-04-16T14:34:29.796Z","CreatedUser":"Helpdesk","ModifiedUser":"Helpdesk","CreatedTime":"2012-04-16T14:34:29.796Z","ModifiedTime":"2012-04-17T15:50:52.499Z"}
]
,"Channel":{"#writable":"false","#connected":"true","#entityId":"0x080e00000136ad8500760af104608064","Name":"Ozone",
"Members":{"Member":[{"#entityOrigin":"System","#entityRef":"0x080e00000136ad8986520af104608052"},{"#entityOrigin":"System","#entityRef":"0x080e00000136bb54ec770af104608028"}]
}}},
{"Event": {"#entityOrigin":"System","#entityId":"0x080e00000136bc3c92d80af104608042","Name":"From2","SymbolCode":"OHVPE----------","TimeObserved":"2012-04-16T19:43:03.150Z","CreatedUser":"Helpdesk","ModifiedUser":"Helpdesk","CreatedTime":"2012-04-16T19:43:03.150Z","ModifiedTime":"2012-04-16T19:43:03.150Z"},
"Channel": {"#writable":"false","#connected":"true","#entityId":"0x080e00000136bc3c92d80af104608034","Name":"Ozone2",
"Members":{"Member":{"#entityOrigin":"System","#entityRef":"0x080e00000136bc3c92d80af104608042"}}}
]}
]}
Is there any way to work with this data? I specifically want all the Events out of it.
Just massage it into the form that the store wants. For example, if you get the data back in a variable called 'data', you could easily just do:
var json = {
identifier: "#entityId",
items: data
};
Then just use the json object in the store.
I can only think of converting your JSON data to JavaScript Object Literal and then add the ID and Name to the JavaScript Object Literal....then convert it into JSON before passing it to your Dojo Store.
I have faced similar issue but i had the luxury to change my service to return JSON with Identifier and Name. I haven't tried what I wrote above.
Related
I am using MongoDB Realm Webhooks to allow for my react app to fetch data from my MongoDB Database. Everything works fine, however the data that I receive is not raw JSON, in the sense that every integer field in the object has an additional property which shows its data type. To better clarify this, I will show an example of the data that is returned:
stats: {
draws: {$numberInt: "1"}
games: {$numberInt: "271"}
goals: {$numberInt: "417"}
losses: {$numberInt: "23"}
}
Is there a way where I am able to parse the data so it can be formatted without the datatype? For example:
stats: {
draws: 1,
games: 271,
goals: 417,
losses: 23,
}
This would improve code readability for my frontend. I've tried to flatten the object manually using an object flatten function, but what I am dealing with is a large nested object, so it is difficult.
Try BSON.Binary.fromText or similar functions. There's not a lot of documentation of the BSON utilities
There are many articles about BizTalk JSON encoder...
I am trying to produce JSON for 3rd party software wanting root level array, like so:
[
{
"property" : "value"
},
{
"property" : "value"
}
]
I am trying to control the output using schema, but I am not able to specify minOccurs and maxOccurs on the root node. I have also tried "Group Max/Min Occurs", with no difference.
Is it not possible to do this?
What about the old newtonsoft hack for adding Array attribute to the output XML? (I have tried this as well, but failed...)
This is similar to BizTalk 2013 - decode JSON array
As per the answers on the other question, you can't have an array at the root node of an XML schema. That one is for receiving a JSON payload with an array at the root, rather then sending one. But your options are similar, you would need to either have a custom pipeline component after the JSON encoder that removes the root or a custom pipeline component that produces the JSON the way you want.
I'm doing the maintenance of an angular website, I have a problem of display in the ng2 smart table , in a column it displays the json of an object, this is the error that the developer has made by receiving the list of transaction where the user and items are a json text,
how can I parse them
ps this is the code :
this.data.doData('transaction','get').subscribe({
next:res=>{
console.log(res);
this.dataSource = [...res['transactions']]
console.log(this.dataSource)
},error:err=>{
console.log(err);
}
})
So actually you are getting the JSON string. To use it just do JSON.parse(items) and JSON.parse(user) and you will get the parsed JSON (array for the items and pbject for the user)
You can also use map in your service file and handle this parsing their so when you subscribe to the data in your component's ts file you will get the parsed form.
UPDATE:
Look at the quotes (quotes matching you would know from basic rules of strings, i.e. either single or double should be enclosing the main string). So when you were JSON parsing the string it wasn't taking it correct format to parse it.
I'm able to successfully generate JSON file from Maximo however I would like to modify the JSON before it gets generated. Like below is the sample JSON that gets generated in Maximo,
{"lastreadingdate":"2020-01-30T16:48:33+01:00",
"linearassetmeterid":0,
"sinceinstall":0.0,
"lastreading":"1,150",
"plustinitrdng":0.0,
"sincelastinspect":0.0,
"_rowstamp":"568349195",
"assetnum":"RS100003",
"active":true,
"assetmeterid":85,
"lifetodate":0.0,
"measureunitid":"KWH",
"metername":"1010",
"remarks":"TESTING JSON"}
I need the JSON to be generated as below ,
{"spi:action": "OSLC draft",
"spi:tri1readingdate":"2020-01-30T16:48:33+01:00",
"spi:tryassetmeterid":0,
"spi:install":0.0,
"spi:lastreadingTx":"1,150",
"spi:intrdngtrX":0.0,
and so on...}
Basically I need to change the target attribute names and prefix "spi" Below is the error occuring in JSON Mapping .
You're not specifying how you generate the JSON file but I'll quickly explain how you can achieve this:
As Dex pointed out, there is a JSON Mapping app in the integration module that you can use to map your outbound object structure's fields to your target structure naming.
You define your JSON structure on the JSON Mapping tab by providing a JSON sample.
You then define your mapping with Maximo on the Properties tab, like this:
Reading this IBM doc before jumping right into it should help you a lot:
https://www.ibm.com/developerworks/community/wikis/form/anonymous/api/wiki/02db2a84-fc66-4667-b760-54e495526ec1/page/e10f6e96-435d-433c-8259-5690eb756779/attachment/169224c7-10a5-4cee-af72-697a476f8b2e/media/JSON
For a sample JSON data which looks like this -
{
"children":{
"Alice":{...},
"Jamie":{...},
"Bob":{...}
// Any new child with a given unique name will be added to this object
},
childrenOrder:["Alice", "Bob", "Jamie"]
}
In the corresponding JSON Schema, I am trying to limit the valid values in "childrenOrder" array to be from the run time children keys.
I didn't see any means of referring to runtime dynamic values in the official JSON Schema documentation (http://json-schema.org/documentation.html).
Is this even possible at the moment?
For the sake of brevity I omitted JSON Schema code. I can add it if folks think it is needed to address the question.
Thanks in advance.
No it is not possible using the current JSON Schema specification. However, there is a proposal for the next version of JSON Schema that could change that.
https://github.com/json-schema/json-schema/wiki/%24data-(v5-proposal)