New line feed in json data - json

I'm having a json file as :-
{
VALUES: [
{
"UTAGID": "SYSTEM_CHILLER1",
"tagName": "P1",
"tagValue": "10",
"tagTime": "2015-07-23T14:29:30.731Z",
"tagQuality": "128"
},
{
"UTAGID": "SYSTEM_CHILLER1",
"tagName": "P1",
"tagValue": "10",
"tagTime": "2015-07-23T14:29:30.731Z",
"tagQuality": "128"
},
{
"UTAGID": "SYSTEM_CHILLER1",
"tagName": "P1",
"tagValue": "10",
"tagTime": "2015-07-23T14:29:30.731Z",
"tagQuality": "128"
}
]
};
where each record is not on a single line.I'm able to retrieve values from a hive table based on this if each record appears on a single line else it shows null values.
What could be the reason?how do I insert new line feed after each record?
Thanks

Related

How to get the index of the object from json file in python

I have a json file with this structure
"user_data": {
"0": {
"user_name": "LinkedIn",
"type": "textfile"
"id": "543211",
"all_tickets": [
"56788",
"43224",
"56788"
]
};
"1": {
"user_name": "stackoverflow",
"type": "textfile"
"id": "123456",
"all_tickets": [
"98134",
"76372",
"44522"
]
}
}
}
Whenever user inputs the same data, I want to check against the existing one in the json file and if it matches, I want to return the index. How can I get it?
For example, if a user inputs the same keys and values of :
"user_name": "LinkedIn",
"type": "textfile"
"id": "543211",
"all_tickets": [
"56788",
"43224",
"56788"
]
The output should be 0(since that is the index)

How to save data in Json format in React-admin v3?

I created JsonInput, which sends a json object to the input SimpleForm, however, a modified version of it gets into the Data Provider.
that's what is sent to the input:
json: {
"FunctionalGroup": [
{
"uaIDref": [
"2104"
],
"_Name": "Текущие параметры",
"_ID": "33"
},
{
"uaIDref": [
"2100"
],
"_Name": "Текущие параметры пониженной точности",
"_ID": "34"
},
],
"_Name": "Прибор 1",
"_ID": "32"
}
that's what came to the server:
json: {
"FunctionalGroup": [
{
"uaIDref": [
"2104"
],
"_Name": "Текущие параметры",
"_ID": "33"
},
{
"uaIDref": [
"2100"
],
"_Name": "Текущие параметры пониженной точности",
"_ID": "34"
}
],
"FunctionalGroupIds": "",
"_Name": "Прибор 1",
"_ID": "32"
},
after a response from the server with this object, this is what came in the field:
json: {
FunctionalGroup: [
{
uaIDref: [
'2104'
]
},
{
uaIDref: [
'2100'
]
}
],
FunctionalGroupIds: ''
}
what kind of magic is this?
I did some tests. When I converted the object to a string, the correct json was sent to the server, however, in the field after the server responded, the modified object was displayed again.
I found out that the conversion is related to redux.js, but what exactly happens is not understood.
Please give any comments on this.
How can I make save json?

How to create nested object in MongoDB schema, nested object and array MEAN stack

I'm trying to design a nested MongoDB schema.
Currently, I have this schema and it's working:
var CompanySchema = new mongoose.Schema({
name: String,
rate: number
date: Date
})
But I wanna expend it to get:
var CompanySchema = new mongoose.Schema({
name: String,
currency: {
mxn: Number,
php: Number,
},
source: [String],
deliveryMethod: [String],
date: Date
})
For source, I want to get an array of inputs ex. ["bank", "debit card", "agent"]
and almost samething for deliverymethod.
But either my input is wrong or my schema, because the value for source saves as one long string, not a separated value.
Also, I think the way I designed the currency to have more currency rate is correct but I don't know how my input json should suppose to be.
I tried it in postman:
{
"name": "google",
"currency": {
"mxn": 20,
"php": 30
}
}
and this is the result i got:
{
"status": 201,
"data": {
"__v": 0,
"name": "google",
"date": "2017-12-06T22:38:45.896Z",
"_id": "5a2871752e3b7343dc388549",
"deliveryMethod": [
null
],
"source": [
null
]
},
"message": "Succesfully Created Company"
}
1- if my currency nested schema is correct how should be my post json file be?
2- how can I get source and deliveryMethod as an array of string?
The JSON in the request body should look like this:
{
"name": "google",
"currency": {
"mxn": 20,
"php": 30
},
"source": ["source1", "source 2", "source 3"],
"deliveryMethod": ["delMetd 1", "delMetd 2", "delMetd 3"],
"date": "2015-11-27T23:00:00Z"
}
I copy/pasted your code and tried with Postman. The response I got back was:
{
"__v": 0,
"name": "google",
"date": "2015-11-27T23:00:00.000Z",
"_id": "5a2915295c5f714f7cb25d90",
"deliveryMethod": [
"delMetd 1",
"delMetd 2",
"delMetd 3"
],
"source": [
"source1",
"source 2",
"source 3"
],
"currency": {
"mxn": 20,
"php": 30
}
}
If I connect to the database with the mongo shell and run db.companies.find().pretty() I get this result:
{
"_id" : ObjectId("5a2915295c5f714f7cb25d90"),
"name" : "google",
"date" : ISODate("2015-11-27T23:00:00Z"),
"deliveryMethod" : [
"delMetd 1",
"delMetd 2",
"delMetd 3"
],
"source" : [
"source1",
"source 2",
"source 3"
],
"currency" : {
"mxn" : 20,
"php" : 30
},
"__v" : 0
}
Your schema is fine. You can try dropping the collection (db.companies.drop()) if you can't get it to work. Start with a fresh one if you don't have any important data in it.

creating JSON object without using a list

I want to be able to create a JSON object so that I can access it like this.
education.schools.UNCC.graduation
Currently, my JSON is like this:
var education = {
"schools": [
"UNCC": {
"graduation": 2015,
"city": "Charlotte, NC",
"major": ["CS", "Spanish"]
},
"UNC-CH": {
"graduation": 2012,
"city": "Chapel Hill, NC"
"major": ["Sociology", "Film"]
}
],
"online": {
"website": "Udacity",
"courses": ["python", "java", "data science"]
}
};
When I go to Lint my JSON, I get an error message.
I know I can reformat my object to access it like this (below), but I don't want to do it this way. I want to be able to call the school name, and not use an index number.
education.schools[1].graduation
Objects have named keys. Arrays are a list of members.
Replace the value of "schools" with an object. Change [] to {}.
This is your JSON corrected.
Your JSON is invalid.
{
"schools": [
{
"UNCC": {
"graduation": "2015",
"city": [
"CS",
"Spanish"
],
"major": [
"CS",
"Spanish"
]
}
},
{
"UNC-CH": {
"graduation": "2012",
"city": [
"Chapel Hill",
"NC"
],
"major": [
"Sociology",
"Film"
]
}
}
],
"online": {
"website": "Udacity",
"courses": [
"python",
"java",
"data science"
]
}
}
Explanation:
"city": "Chapel Hill, NC" -> this is a array with 2 values "Chapel Hill" and "HC", like you do with major and courses.
The Schools array, you need to use this sintaxe to construct a array [{
http://adobe.github.io/Spry/samples/data_region/JSONDataSetSample.html

Parse a json file with nested indexes and save as csv

So, I have a json file with nested indexes. There's an index called "user" which has a subindex called "lang", along with a lot of other subindexes. I only want to extract the "lang" fields out and save it as csv. For the saving as csv part, I can use one of the open source "json2csv" codes, I guess. Could someone help me out with extracting the "lang" fields?
Use JSON.stringify() to convert the data into a string, then use match with a RegExp to return an array of specified key/value pairs. Here is an example:
var foo = JSON.stringify({
"Region": {
"filterField": "kw_Region",
"filterValues": [
"aa",
"bb"
]
},
"ApplicationName": {
"filterField": "kw_ApplicationName",
"filterValues": [
"aa",
"bb"
]
},
"IssueType": {
"filterField": "kw_IssueType",
"filterValues": [
"aa",
"bb"
]
},
"Outage": {
"filterField": "kw_Outage",
"filterValues": [
"aa",
"bb"
]
},
"Priority": {
"filterField": "kw_Priority",
"filterValues": [
"aa",
"bb"
]
}
}).match(/(?=filterValues)[^\]]*./g)
console.log(foo) // ["filterValues":["aa","bb"]", "filterValues":["aa","bb"]", "filterValues":["aa","bb"]", "filterValues":["aa","bb"]", "filterValues":["aa","bb"]"]