How to parse multi dimension array into Talend - talend

I have array which I need to parse into Talent
{
"sEcho": 1,
"iTotalRecords": 54,
"iTotalDisplayRecords": 54,
"aaData": [
[
"79",
"testowy2",
"testowy samochod",
"12.00",
"14.00",
"2147483647",
"posciel",
""
]
]
}
What would be Xpath Query which I need to pass on the tExtractJSONFields ?

you might use JSONPath query to read the multi dimensional array via tExtractJSONFields.
For query building (with respect to above data), please refer below screen shot :
you will get the array in "id" field.
Let me know if you face any problem.

It is not possible to do this,
"Please check right XPathExpression or XML source document." error is occuring...
Your input is a valid json but not a valid XML Document

Related

JSON data getting retrieved from mongodb with formats added explicitly inside field e.g.({"field": {$numberInt: "20"}}). How to process that data?

I have used mongo import to import data into mongodb from csv files. I am trying to retrieve data from an Mongodb realm service. The returned data for the entry is as follows:
{
"_id": "6124edd04543fb222e",
"Field1": "some string",
"Field2": {
"$numberDouble": "145.81"
},
"Field3": {
"$numberInt": "0"
},
"Field4": {
"$numberInt": "15"
},
"Field5": {
"$numberInt": "0"
}
How do I convert this into normal JSON by removing $numberInt and $numberDouble like :
{
"_id": "6124edd04543fb222e",
"Field1": "some string",
"Field2": 145.8,
"Field3": 0,
"Field4": 15,
"Field5": 0
}
The fields are also different for different documents so cannot use Mongoose directly. Are there any solutions to this?
Also would help to know why the numbers are being stored as $numberInt:"".
Edit:
For anyone with the same problem this is how I solved it.
The array of documents is in EJSON format instead of JSON like said in the upvoted answer. To covert it back into normal JSON, I used JSON.stringify to first convert each document I got from map function into string and then parsed it using EJSON.parse with
{strict:false} (this option is important)
option to convert it into normal JSON.
{restaurants.map((restaurant) => {
restaurant=EJSON.parse(JSON.stringify(restaurant),{strict:false});
}
EJSON.parse documentation here. The module to be installed and imported is mongodb-extjson.
The format with $numberInt etc. is called (MongoDB) Extended JSON.
You are getting it on the output side either because this is how you inserted your data (meaning your inserted data was incorrect, you need to fix the ingestion side) or because you requested extended JSON serialization.
If the data in the database is correct, and you want non-extended JSON output, you generally need to write your own serializers to JSON since there are multiple possibilities of how to format the data. MongoDB's JSON output format is the Extended JSON you're seeing in your first quote.

How do I use ADF copy activity with multiple rows in source?

I have source which is JSON array, sink is SQL server. When I use column mapping and see the code I can see mapping is done to first element of array so each run produces single record despite the fact that source has multiple records. How do I use copy activity to import ALL the rows?
"enableStaging": false,
"translator": {
"type": "TabularTranslator",
"schemaMapping": {
"['#odata.context']": "BuyerFinancing",
"['#odata.nextLink']": "PropertyCondition",
"value[0].AssociationFee": "AssociationFee",
"value[0].AssociationFeeFrequency": "AssociationFeeFrequency",
"value[0].AssociationName": "AssociationName",
Use * as the source field to indicate all elements in json format. For example, with json:
{
"results": [
{"field1": "valuea", "field2": "valueb"},
{"field1": "valuex", "field2": "valuey"}
]
}
and a database table with a column result to store the json. The mapping with results as the collection and * and the sub element will create two records with:
{"field1": "valuea", "field2": "valueb"}
{"field1": "valuex", "field2": "valuey"}
in the result field.
Copy Data Field Mapping
ADF support cross apply for json array. Please check the example in this doc. https://learn.microsoft.com/en-us/azure/data-factory/supported-file-formats-and-compression-codecs#jsonformat-example
For schema mapping: https://learn.microsoft.com/en-us/azure/data-factory/copy-activity-schema-and-type-mapping#schema-mapping

Cloudant Query: Access data in nested array AND sort by if-statement

I have a question pertaining to how to query in cloudant with (1) a nested array and (2) sort by using an if-statement. I have been to the following websites, but I still need assistance.
https://docs.cloudant.com/guides/cloudant-query.html
https://docs.cloudant.com/api/cloudant-query.html
I want to return the documents that meet satisfy the following pseudo code:
if event[i].type == "check_in" then sort by event[i].time
Here is a snippet of the JSON data structure that I am using.
{
"status" : "active",
"event": [
{
"type": "check_in",
"time": "11/19/2014 15:34:12"
},
{
"type": "check_out",
"time": "11/20/2014 17:54:22"
}
]
}
Here are some questions I have that may break this problem down:
(1) How can I access event[0].type data?
(2) How can I loop through the entire event array inside of a Cloudant Query and check if event[i] == "check_in" for each object in the event array?
(3) How can I sort on the timestamp data (assume it is an integer for simplicity)?
(4) What format does the timestamp have to be in for me to sort it in a Cloudant Query?
Could you help point me in the right direction to help accomplish this? Please let me know if you need more information.
Cloudant Query doesn't seem to work with indexing array elements and query against.
You can create a View to get the same result by indexing each array elements and then query on the View.

querying on internals in mongo

I have document structure like:
{ "_id": { "$oid" : "51711cd87023380037000001" },
"dayData": "{ "daysdata":{"date":"02-12-2013","week_day":"","month":"","date_day":"","year":"2013"}}"
}
I want to extract document having date = "02-12-2013" in the above. Here i am trying to query on a value which is also a json.
Please let me know how to use mongodb java driver to extract this
Not answer (stackoverflow won't let me comment as I don't have enough points!)
Your string containing json has a syntax error.
There is a single " after "year":"2013"
You may have to fix that 1st.

JSON-Framework Parsing data in a strange order

I currently have an ordered JSON string being passed into my iPhone app, which is then being parsed using the JSON Framework.
The data is as follows:
"league_table": object{
"Premiership": array[6],
"Championship": array[6],
"Division 1": array[6],
"Division 2": array[6],
"Division 3": array[6]
}
However when it parses that, it throws out a weird order.
Division 2
Division 1
Championship
"Division 3"
Premiership
Which I got by calling : NSLog(#"%#",[dictionaryValue allKeys]);.
Has anyone experienced this before? Any idea what to do to sort it again?
UPDATE ::
The shortened UN-Parsed JSON is here :
{"league_table":
{
"Premiership":[],
"Championship":[],
"Division 1":[],
"Division 2":[],
"Division 3":[]}
}
As far as I can tell, this is a Key/Value Pair, so it should be parsed in the same order.
For instance going to http://json.parser.online.fr/ and pasting that in will parse it in the correct order.
However the JSON-Framework doesn't parse it the same, it parses it in a strange order with no real sorting going on
JSON object fields don't have a defined order. If you want key/value pairs in a defined order, there are basically two options:
An array of single-field objects:
[{"Premiership": array[6]},
{"Championship": array[6]},
{"Division 1": array[6]},
{"Division 2": array[6]},
{"Division 3": array[6]}]
An array of key/value pairs:
[["Premiership", array[6]],
["Championship", array[6]],
["Division 1", array[6]],
["Division 2", array[6]],
["Division 3", array[6]]]
Sidenote: I'm half-guessing that the relationship between the sample data and JSON. I don't know what object and array[6] are doing there.
Yep, I've seen that before.
Does this cause you a problem? it looks like a Dictionary (keyed) .. so I guess your application just accesses the required elements by it's key.
I believe a JSON array format would maintain the order.
EDIT
Ok, so you need to maintain the order ... but from what you say, it looks like the key isn't important.
Are you in control of the creation of the JSON string ? If so, could you present the data like this :
[
{
"leagueName":"Premiership",
"leagueLines":[...]
},
{
"leagueName":"Championship",
"leagueLines":[...]
},
{
"leagueName":"League One",
"leagueLines":[]
},
... etc ....
]
I've put in the leagueName in just for information ... who know's you might need it for something :)
Good Luck