What is my JSON file consist of? - json

I have read tutorials on the syntax of JSON files but I am still not quite sure I got it. Here is my JSON file:
{
"dataset": [
{
"seriesname": "Item1 Price",
"data": [
{
"value": 4.72
},
{
"value": 2.81
},
{
"value": 6.18
},
{
"value": 5.17
},
{
"value": 2.94
},
{
"value": 3.77
},
{
"value": 1.7
},
{
"value": 6.72
},
{
"value": 4.61
}
]
},
{
"seriesname": "Item2 Price",
"data": [
{
"value": 2.49
},
{
"value": 0.72
},
{
"value": 4.06
},
{
"value": 1.74
},
{
"value": 7.23
},
{
"value": 5.83
},
{
"value": 2.59
},
{
"value": 7.54
},
{
"value": 7.02
}
]
}
],
"categories": [
{
"label": "Jan"
},
{
"label": "Feb"
},
{
"label": "Mar"
},
{
"label": "Apr"
},
{
"label": "May"
},
{
"label": "Jun"
},
{
"label": "Jul"
},
{
"label": "Aug"
},
{
"label": "Sept"
}
]
}
From what I understand, there are 2 JSONObjects here, one is "dataset" and another is "categories". The "dataset" object has 2 JSONObjects inside it (Item1 Price and Item2Price) and they both are arrays which have several values. "categories" is an array with several entries. Am I correct or am I misreading the file?

You're correct. You can use any of the JSON visualizers out there (just google that term) to 'see' the data structure of the JSON array...
for example the one I use often is located here.
if you paste your JSON data in the left column, then click the arrow in the middle pointing to the right, it will let you navigate and explore the data easily (see screenshot below).
When I started working with JSON it really helped me visualize the syntax and structure of some complex data I was working with.
Good luck!

Related

Reformat JSON object using Dart

I need to standardize the object response key/values so that they are easier to parse/traverse using the tool I'm integrating.
Starting with the following JSON:
{
"status": true,
"body": {
"phone": "+1 937-830-1167",
"address": "2323 kuhku",
"linkedin": "uhku",
"twitter": "uhukh",
"education": "weeww",
"work_experience": "wewaew",
"write_something_about_you": "yugtyt",
"why_you_think_you_are_good_for_this_job": "kuhhuk",
"write_your_assignment_question": "kuhghuhghj",
"upload_your_attachment": null,
"upload_your_resume_here": null
}
}
Using Dart, what would be the best way to reformat as shown?
{
"status": true,
"body": {
"answers":[
{
"label": "phone",
"answer":"+1 937-830-1167"
},
{
"label": "address",
"answer":"2323 kuhku"
},
{
"label": "linkedin",
"answer": "uhku"
},
{
"label": "twitter",
"answer": "uhku"
},
{
"label": "education",
"answer": "uhku"
},
{
"label": "work_experience",
"answer": "uhku"
},
{
"label": "write_something_about_you",
"answer": "uhku"
},
{
"label": "why_you_think_you_are_good_for_this_job",
"answer": "uhku"
},
{
"label": "write_your_assignment_question",
"answer": "uhku"
},
{
"label": "upload_your_attachment",
"answer": "uhku"
},
{
"label": "write_something_about_you",
"answer": "upload_your_resume_here"
}
]
}
}
I'm somewhat limited by the tool I'm using so this will make it much easier to parse the JSON object with JSON Path as needed.
Looks like something that should be easily doable as:
var json = ... your json ...;
var result = {
"status": json["status"],
"body": [for (var e in json["body"].entries)
{"label": e.key, "answer": e.value}
]
};
Create a new JSON object with the same "status" and a "body" which is a list instead of a map, and for each entry in the original map, create a JSON object with a "label" and "answer" taken from the key and value of the map entry.

How to filter json file with specific tag values and get output into csv

I have created a json file with the output having key values pair. But I would like to filter more and get only specific tags and get new output in table using excel (csv) format
aws resourcegroupstaggingapi get-resources --tags-per-page 100 --tag-filters Key=ProjectName,Values=Avengers > tag-filter.json
However it provides the list of all the tags besides "ProjectName". I would like to filter the output with 2 more tags with their values but not all of them:
Actual results:
{
"ResourceTagMappingList": [
{
"ResourceARN": "arn:aws:app:us-east-1:XXXX/mesh/Avenger1",
"Tags": [
{
"Key": "ApplicationName",
"Value": "HULK"
},
{
"Key": "Owner",
"Value": "Mark Ruffalo"
},
{
"Key": "Costume",
"Value": "GREEN"
},
{
"Key": "Power",
"Value": "SMASH"
},
{
"Key": "ProjectName",
"Value": "Avengers"
}
]
},
{
"ResourceARN": "arn:aws:app:us-east-1:XXXX:mesh/Avenger2",
"Tags": [
{
"Key": "ApplicationName",
"Value": "IRON-MAN"
},
{
"Key": "Owner",
"Value": "Robert Downey Jr."
},
{
"Key": "Costume",
"Value": "RED"
},
{
"Key": "Power",
"Value": "SuperSonic"
},
{
"Key": "ProjectName",
"Value": "Avengers"
}
]
}
]
}
Expected Results:
{
"ResourceTagMappingList": [
{
"ResourceARN": "arn:aws:app:us-east-1:XXXX/mesh/Avenger1",
"Tags": [
{
"Key": "ApplicationName",
"Value": "HULK"
},
{
"Key": "Owner",
"Value": "Mark Ruffalo"
},
{
"Key": "ProjectName",
"Value": "Avengers"
}
]
},
{
"ResourceARN": "arn:aws:app:us-east-1:XXXX:mesh/Avenger2",
"Tags": [
{
"Key": "ApplicationName",
"Value": "IRON-MAN"
},
{
"Key": "Owner",
"Value": "Robert Downey Jr."
},
{
"Key": "ProjectName",
"Value": "Avengers"
}
]
}
]
}
To achieve the "expected" output given the "actual" output, you could use the following filter:
.ResourceTagMappingList[].Tags
|= map(select(.Key|IN("ApplicationName","Owner","ProjectName")))
To achieve the expected CSV, it would be helpful to know what you expect.

Acumatica API - Creating an appointment detail marked for PO

I want to create an appointment detail line that is marked for PO. I'm setting the fields I think are relevant, but after the PUT, the MarkforPO field will reset to false. The detail record is created, but not marked for PO or any errors returned. Is there a process or specific field/value that I am missing?
Here is my Appointment PUT JSON:
{
"id": "[APPOINTMENT GUID]",
"Details": [
{
"LineRef": {
"value": "0003"
},
"LineNbr": {
"value": 3
},
"LineType": {
"value": "Non-stock item"
},
"MarkforPO": {
"value": true
},
"POSource": {
"value": "Purchase to Appointment"
},
"InventoryID": {
"value": "INVID"
},
"Description": {
"value": "INVENTORY DESC"
},
"EstimatedQty": {
"value": "1"
},
"Billable":{
"value":true
},
"UnitPrice": {
"value": "25"
},
"BillableQty": {
"value": "1"
},
"BillableAmount": {
"value": "25"
},
"UnitCost": {
"value": "25"
},
"VendorID": {
"value": "AASERVICES"
},
"VendorLocationID": {
"value": "MAIN"
}
}
]
}
The trouble was that the AppDetails.MarkforPO field was not linked to a field but mapped to FSSODet__EnablePO instead. I am not sure what this is but after adding adding another custom field directly mapped to Mark for PO I was able to modify this field through the API.

Expecting 'EOF', '}', ',', ']', got 'STRING'

I am trying to add some code but it turns out I cant add these two together, I am new to JSON and coding in general, anyhelp?
"playerStatProgression": [{
"name": "HalloweenKillerVialRepetitions"
}, {
"name": "HalloweenSurvivorVialRepetitions",
"value": 1
}, {
"name": "DBD_HalloweenSurvivorToxin"
}],
"specialEvent": [{
"eventId": "Halloween2018",
"seenCinematics": [0]
}],
"versionNumber": 7
}
"playerStatProgression": [{
"name": "DBD_GoldenCoin",
"value": 89
}, {
"name": "DBD_BurntCoin",
"value": 53
}, {
"name": "DBD_SummerKillerCoin",
"value": 71
}, {
"name": "DBD_SummerSurvivorCoin",
"value": 112
}], "versionNumber": 7
}
You're supposed to wrap your JSON object in curly braces ({}) because a JSON file can only contain one object. Also, it seems invalid. Put it through a validator to figure out the issues.
You can do this in this way:
[
{
"playerStatProgression": [
{
"name": "HalloweenKillerVialRepetitions"
},
{
"name": "HalloweenSurvivorVialRepetitions",
"value": 1
},
{
"name": "DBD_HalloweenSurvivorToxin"
}
],
"specialEvent": [
{
"eventId": "Halloween2018",
"seenCinematics": [
0
]
}
],
"versionNumber": 7
},
{
"playerStatProgression": [
{
"name": "DBD_GoldenCoin",
"value": 89
},
{
"name": "DBD_BurntCoin",
"value": 53
},
{
"name": "DBD_SummerKillerCoin",
"value": 71
},
{
"name": "DBD_SummerSurvivorCoin",
"value": 112
}
],
"versionNumber": 7
}
]

Jsonpath querying only one item

I have a problem to find out only a determined value in a json using jsonpath.
I have this json:
{"tvs": {
{ "tv": [
{
"serial": "HD1300",
"data": [
{
"title": "manufacturer",
"value": "lg"
},
{
"title": "color",
"value": "silver"
},
{
"title": "inches",
"value": 32
},
{
"title": "connection",
"value": 220
},
{
"title": "connection",
"value": 400
}
]
}.. more tvs
And I want to know if the value connection:400 is present for serial hd1300
I already tried with:
$.tvs.[?(#.serial=='hd1340')].data.[?(#.title== 'connection'),(#.value==400)]
But my problem is that I retrieve also the "connection" with 200. How can I filter to get only this value?
I think you might have an error in your JSON (extra brace between tvs and tv). I was able to get this to work on http://jsonpath.com.
{"tvs":
{ "tv": [
{
"serial": "HD1300",
"data": [
{
"title": "manufacturer",
"value": "lg"
},
{
"title": "color",
"value": "silver"
},
{
"title": "inches",
"value": 32
},
{
"title": "connection",
"value": 220
},
{
"title": "connection",
"value": 400
}
]}
]}
}
$.tvs.tv.[?(#.serial=='HD1300')].data.[?(#.title=='connection' && #.value=='400')]