Nested JSON Format - json

I have a data Called 'Village'.
Country:
{
State:{
District:{
Taluk:{
Village: String
}
}
}
}
Is this correct JSON format for Data "Village".

Following is the modified json to make it valid
{
"Country": {
"State": {
"District": {
"Taluk": {
"Village": "String"
}
}
}
}
}
and to validate any json string use http://jsonlint.com/

You don't declare types such as String in JSON. Also, you need to quote your variable names. It seems like your declaring a structure in JSON. I would replace String with an empty string, that is essentially declaring the type:
{"Country":
{
"State":{
"District":{
"Taluk":{
"Village": ""
}
}
}
}
}

Related

JMeter - How to convert string value to a list

I have an API that returns the following json:
{
"GetAppendixListResponse": {
"GetAppendixListResult": {
"FileList": {
"string": ["3602","3587"]
},
"Code": "0"
}
}
}
The debug sampler looks like:
JMeterVariables:
AppendixCode_1=["3602","3587"]
AppendixCode_ALL=["3602","3587"]
AppendixCode_matchNr=1
How can I convert ["3602","3587"] from string to a list (for loop_controller)?

MongoDB: Variable nested in several objects

I have a problem creating a query in MongoDB. I have the following JSON. How to ask mongodb question to get _id from level5 object?
{
"Id": "1",
"level1": {
"level2": {
"level3": {
"level4": {
"level5": {
"_id": 2
}
}
}
}
}
}
You can use the dot notation to get value from nested object:
db.collection.aggregate([
{
$project: {
value: "$level1.level2.level3.level4.level5._id"
}
}
])
Mongo Playground

How to create Interface for Nested JSON Object

I am having a Nested JSON Object and I need to create the Interface and Use that in my TS File...
{
"states":[
{
"location":"banglore",
"weather":{
"place":{
"heat":40,
"cold":60,
"place":"banglore"
}
}
},
]
}
Try this one
`export interface States{
"states":[
{
"location": string,
"weather":{
"place":{
"heat":number,
"cold":number,
"place":string
} }
}
]
}`

Struggling to parse response from API service

Struggling to parse what appears to be a simple response from an API service (GraphQL / JSON). The response is retrieved as String based on HTTP request, and have tried different approaches (using both JsonObject/JsonParse and JsonArrayfrom com.google.gsonlibrary to get desired string elements to String, although without being able to extract anything.
Anyone willing to share suggestions how to parse and get "total" and "startsAt" from the response shown below?
{
"data": {
"viewer": {
"homes": [
{
"currentSubscription": {
"priceInfo": {
"current": {
"total": 0.5626,
"energy": 0.4336,
"tax": 0.129,
"startsAt": "2019-11-14T20:00:00+01:00"
}
}
}
}
]
}
}
}
You can get the json value like this
Assign the response to some variable like res.
For ex :
var res = {
"data": {
"viewer": {
"homes": [
{
"currentSubscription": {
"priceInfo": {
"current": {
"total": 0.5626,
"energy": 0.4336,
"tax": 0.129,
"startsAt": "2019-11-14T20:00:00+01:00"
}
}
}
}
]
}
}
var total=res.data.viewer.homes[0].currentSubscription.priceInfo.current.total;
var startAt = res.data.viewer.homes[0].currentSubscription.priceInfo.current.startsAt;
console.log('total is: ',total);
console.log('startsAt: ', startsAt)

how to declare two arrays in json?

I want to create a json string for my web application. Actually i am new to this json format.In my json string i have to create two arrays in my json structure.But i have some syntax problem in creating two arrays. my json string is given below for your reference.
{
MarkUpdate:[
{
'FinalMarks':[
{
'studentId':'S1',
'Ques_Mark':[
{
'qId' :'Q1',
'mark':'14',
},
{
'qId':'Q2',
'mark':'10',
}
]
},
{
'studentId':'S2',
'Ques_Mark':[
{
'qId' :'Q1',
'mark':'12',
},
{
'qId':'Q2',
'mark':'13',
}
]
}
]
}
]
}
In my above json string format,my MarkUpdate contains one array object named as FinalMarks.So,here i have to create one more array object named as EvalMarks under MarkUpdate.
Acually my EvalMarks contains following elements...
'EvalMarks':[
{
'EvalId':'E1',
'Ques_Mark':[
{
'qId' :'Q1',
'studId':'S1',
'mark':'13',
},
{
'qId':'Q2',
'studId':'S1',
'mark':'13',
}
]
},
{
'EvalId':'E2',
'Ques_Mark':[
{
'qId' :'Q1',
'studId':'S2',
'mark':'10',
},
{
'qId':'Q2',
'studId':'S2',
'mark':'10',
}
]
}
]
So, i have declare this EvalMarks under the MarkUpdate.I missed the syntax...
Could you plz tell me how to add this array object under the MarkUpdate.
guide me to get out of this issue...
To declare two arrays in one JSON object, remember that the JSON object can only be a single object, therefore the array must be inside the enclosing curly braces. For example:
{
"array1":[1,2,3],
"array2":["jim","louise","mark"]
}
For your case, it's important to remember that you should properly indent your braces, square and curly, so that you can visually identify mistakes before they become problems. I stringly recommend http://jslint.com/ to validate your JSON before using it. It's also great for Javascript:
{
"MarkUpdate":[
{
"FinalMarks":[
{
"studentId":"S1",
"Ques_Mark":[
{
"qId" :"Q1",
"mark":"14"
},
{
"qId":"Q2",
"mark":"10"
}
]
},
{
"studentId":"S2",
"Ques_Mark":[
{
"qId" :"Q1",
"mark":"12"
},
{
"qId":"Q2",
"mark":"13"
}
]
}
]
}
],
"EvalMarks":[
{
"EvalId":"E1",
"Ques_Mark":[
{
"qId" :"Q1",
"studId":"S1",
"mark":"13"
},
{
"qId":"Q2",
"studId":"S1",
"mark":"13"
}
]
},
{
"EvalId":"E2",
"Ques_Mark":[
{
"qId" :"Q1",
"studId":"S2",
"mark":"10"
},
{
"qId":"Q2",
"studId":"S2",
"mark":"10"
}
]
}
]
}
Its not a valid JSON if you have commas after the last key-value pair in an object. I would start by knocking off all those unnecessary commas after the last key-value pairs inside most of your objects and validating the JSON in www.jslint.com
To be more clear ,
{
"qId":"Q2",
"studId":"S2",
"mark":"10",
}
is Not Valid.
On the other hand,
{
"qId":"Q2",
"studId":"S2",
"mark":"10"
}
Is valid.