Getting 404 while using json-server - json

I am learning to use json-server npm package.
I am using latest json-server version 0.17.0.
I want to get this data from url "http://localhost:3001/getFolderByFolder/14".Where 14 should match with folder_id.
{
"folder_id": 14,
"abstracts": {
"33": {
"abstract_name": "abstractt1",
},
"34": {
"abstract_name": "abstract2",
},
"35": {
"abstract_name": "abstract3",
}
},
"folder_name": "folder2",
"number_of_items": 2,
"user_id": 6
}
I created db.json.I wrote this inside.
{
"folders": {
"folder_id": 14,
"abstracts": {
"33": {
"abstract_name": "abstractt1",
},
"34": {
"abstract_name": "abstract2",
},
"35": {
"abstract_name": "abstract3",
}
},
"folder_name": "folder2",
"number_of_items": 2,
"user_id": 6
}
}
I created route.json in same folder.I wrote this inside.
{
"routes": {
"/getFolderByFolderId/:id": "/folders?folder_id=:id"
}
}
I typed this command json-server --watch db.json --routes route.json --port 3001
I get 200 when http://localhost:3001/folders?folder_id=14.
Then why i am getting 404 on http://localhost/getFolderByFolderId/14.
I tried to change db.json as
{
"folders": [{
"folder_id": 14,
"abstracts": {
"33": {
"abstract_name": "abstractt1",
},
"34": {
"abstract_name": "abstract2",
},
"35": {
"abstract_name": "abstract3",
}
},
"folder_name": "folder2",
"number_of_items": 2,
"user_id": 6
}]
}
Still getting 404.

I dont believe you need the routes: {} object in routes.json. Just simply your custom route inside an empty object like so:
{
"/getFolderByFolderId/:id": "/folders?folder_id=:id"
}
Reference: https://shekhargulati.com/2019/07/10/how-to-setup-json-server-to-use-custom-id-and-route/
Also I just noticed when you mentioned having trouble with your route that you didnt mention utilizing a port number:
Blockquote I get 200 when http://localhost:3001/folders?folder_id=14.
Then why i am getting 404 on http://localhost/getFolderByFolderId/14
Of course make sure that is formatted properly as well.

Related

Create POJO Class for JSON

Below is the json object, I need to create the pojos. I had tried couple of things but not able to find anything relevant. Here the key itself is varying/dynamic
{
"ABC" : {
"values": {
"orr": {
"data": {
"1574065955000": 0.2,
"1574066955000": 0.34,
"1574067955000": 0.6899
}
},
"cpu": {
"data": {
"1574065955000": None,
"1574067955000": None
}
}
}
},
"DEF" : {
"values": {
"ups": {
"data": {
"1574065955000": 0.01,
"1574066955000": 0.09
}
},
"cpu": {
"data": {
"1574065955000": 0.09,
"1574066955000": 0.04,
"1574067955000": 0.0,
"1574068955000": 0.001
}
}
}
},
"scores_reference": {
"low_deviations": "0.0 - 0.4",
"moderate_deviations": "0.4 - 0.7",
"high_deviations": "0.7 - 1.0"
}
}
Can someone please suggest how can I create the pojos ? I tried multiple things but is not working out for me.
You can use any online JSON to POJO converter links and paste you sample JSON to get the corresponding POJO. following are some of the links :
http://pojo.sodhanalibrary.com/
http://www.jsonschema2pojo.org/
https://www.freecodeformat.com/json2pojo.php

GraphQL Query returns null objects both in GraphiQL and App from JSON data source

I'm trying to get my mocked JSON data via GraphQL in Gatsby. The response shows the correct data, but also two null objects as well. Why is it happening?
I'm using the gatsby-transformer.json plugin to query my data and gatsby-source-filesystem to point the transformer to my json files.
categories.json
the mock file I'm trying to get to work :)
{
"categories": [
{
"title": "DEZERTY",
"path": "/dezerty",
"categoryItems": [
{
"categoryName": "CUKRIKY",
"image": "../../../../static/img/dessertcategories/cukriky.jpg"
},
{
"categoryName": "NAHODNE",
"image": "../../../../static/img/dessertcategories/nahodne.jpg"
},
]
},
{
"title": "CANDY BAR",
"path": "/candy-bar",
"categoryItems": [
{
"categoryName": "CHEESECAKY",
"image": "../../../../static/img/dessertcategories/cheesecaky.jpg"
},
{
"categoryName": "BEZLEPKOVÉ TORTY",
"image": "../../../../static/img/dessertcategories/bezlepkove-torty.jpg"
},
]
}
]
}
GraphQL query in GraphiQL
query Collections {
allMockJson {
edges {
node {
categories {
categoryItems {
categoryName
image
}
title
path
}
}
}
}
}
And the response GraphiQL gives me
{
"data": {
"allMockJson": {
"edges": [
{
"node": {
"categories": null
}
},
{
"node": {
"categories": null
}
},
{
"node": {
"categories": [
{
"categoryItems": [
{
"categoryName": "CHEESECAKY",
"image": "../../../../static/img/dessertcategories/cheesecaky.jpg"
},
{
"categoryName": "BEZLEPKOVÉ TORTY",
"image": "../../../../static/img/dessertcategories/bezlepkove-torty.jpg"
}
],
"title": "DEZERTY",
"path": "/dezerty"
},
{
"categoryItems": [
{
"categoryName": "CUKRIKY",
"image": "../../../../static/img/dessertcategories/CUKRIKY.jpg"
},
{
"categoryName": "NAHODNE",
"image": "../../../../static/img/dessertcategories/NAHODNE.jpg"
}
],
"title": "CANDY BAR",
"path": "/candy-bar"
}
]
}
}
]
}
}
}
I expected only to get the DEZERTY and CANDY BAR sections. Why are there null categories and how do I fix it?
Thanks in advance
Your JSON contains syntax errors in the objects DEZERTY and CANDY BAR. It silently fails without telling you. Try this json linter.
Error: Parse error on line 12: },
Error: Parse error on line 25: },
Try again. Your query should work now.
You should look into an IDE that highlights these types of errors and saves you time and frustration.

How Do I Display Non-Lit Material + Texture Using LMV Toolkit Specification or a Autodesk Material Library Material?

I'm unable to successfully display a model+texture map WITHOUT the viewer applying lighting effects to it.
I am using a localised version of the viewer to investigate the problem but I welcome an Autodesk Material Library setting solution if it exists.
This is an example of how I want to see the material, i.e. no specular, no reflections (ignore the fact this example is in three.js): https://stemkoski.github.io/Three.js/Texture-Repeat.html
This is an example of my problem: https://myhub.autodesk360.com/ue29c31db/g/shares/SHabee1QT1a327cf2b7a7879b97973545818?viewState=NoIgbgDAdAjCA0IBGMAsBmATAMwKYBMBaCAQwHYBjQ1fATlUNt13UO1pIwDYZMAOTCVogAukA
I have attempted many different "Autodesk Material Library" settings, including ramping up "Self Illumination" however, the texture either fails to load and/or, that glossy shine persists.
Could the Materials.json be tweaked to fix this problem?
This is my Materials.json
{
"name": "LMVTK Simple Materials",
"version": "1.0",
"scene": {
"SceneUnit": 8214,
"YIsUp": 2
},
"materials": {
"0": {
"version": 2,
"userassets": ["0"],
"materials": {
"0": {
"tag": "0",
"proteinType": "",
"definition": "SimplePhong",
"properties": {
"integers": {
"mode": 4
},
"booleans": {
"color_by_object": false,
"generic_is_metal": false,
"generic_backface_cull": false
},
"scalars": {
"generic_transparency": {
"units": "",
"values": [0]
}
},
"colors": {
"generic_diffuse": {
"values": [{
"r": 1,
"g": 1,
"b": 1,
"a": 1
}]
}
}
},
"transparent": false,
"textures": {
"generic_diffuse": {
"connections": ["1_generic_diffuse"]
}
}
},
"1_generic_diffuse": {
"tag": "0",
"definition": "UnifiedBitmap",
"properties": {
"scalars": {
"unifiedbitmap_RGBAmount": {
"units": "",
"values": [1]
}
},
"uris": {
"unifiedbitmap_Bitmap": {
"values": ["image0.jpg"]
}
},
"booleans": {
"texture_URepeat": true,
"texture_VRepeat": true,
"unifiedbitmap_Invert": false
},
"integers": {
"texture_MapChannel": 1
}
}
}
}
}
}
}
I recommend trying this approach. Literally bypass the LMV materials (which are all effected by lighting) and use a custom THREE material that is not effected by lighting. You may possibly need to create a custom shader too.
Start with this...
https://forge.autodesk.com/cloud_and_mobile/2016/02/custom-transparent-meshes-with-view-data-api.html
Let me know if that fixes the problem, and if not I can deep dive into it further.
Best, Michael

Put Items using Json File in AWS DynamoDB using AWS CLI

While putting below JSON in dynamo DB using AWS CLI with below command:
aws dynamodb put-item --table-name ScreenList --item file://tableName.json
I am getting Parameter validation failed Exception.I have gone rigorously through AWS docs but failed to find example to insert a complicated json.Every small help is welcome.
The updated Json :
{
"itemName": {
"S": "SCREEN_LIST"
},
"productName": {
"S": "P2P_MOBITEL"
},
"screenList": {
"L": [
{
"menu": {
"L": [
{
"M": {
"menuId": {
"N": "1"
},
"menuText": {
"S": "ENG_HEADING"
},
"menuType": {
"S": "Dynamic"
}
}
}
]
},
"M": {
"screenFooter": {
"S": "F_LANGUAGE_CHANGE"
},
"screenHeader": {
"S": "H_LANGUAGE_CHANGE"
},
"screenId": {
"S": "LANGUAGE_CHANGE"
},
"screenType": {
"S": ""
}
}
}
]
}
}
It seems that you are defining complex types incorrectly. According to AWS documentation you should define a list like this:
"L": ["Cookies", "Coffee", 3.14159]
and a map should be defined like this:
"M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}}
which means that a menu map should be defined like this:
"menu": {
"L": [
{
"M": {
"menuId": {"N" :"1"},
"menuText": {"S" :"PACKS_SCREEN"},
"menuType": {"S" :"Dynamic"}
}
}
]
}
Notice the "M" and "L" attributes.
You should change the rest of your JSON in a similar fashion.
You can find full JSON definition here in the Options section.
UPDATE
Now your list definition is incorrect. You have:
"screenList":{
"L":[
{
"menu":{ ... },
"M":{ ... }
}
]
}
While it should be:
"screenList":{
"L":[
{
"M":{ ... }
},
{
"M":{ ... }
},
]
}

trouble with parseing JSON with ASPJSON for classic ASP

I am using ASP JSON at http://www.aspjson.com/
I am trying to parse the salehistory the out of this JSON response below. I can get all the nodes under the property object like this
oJSON.data("property").item(0).item("vintage").item("lastModified")
However when I try to go deeper I get errors
I have tried
oJSON.data("property").item(0).item("salehistory").item("salesearchdate") but that does not return anything.
I think that it has something to do with the fact that property is an object and SalesHistory is an object inside of Property however I cannot seem to get the values out of the salehistory level.
Below is the JSON structure that I am trying to parse. Any help would be appreciated. .
{
"status": {
"version": "1.0.0",
"code": 0,
"msg": "SuccessWithResult",
"total": 1,
"page": 1,
"pagesize": 10
},
"property": [
{
"identifier": {
"obPropId": 3464768712115,
"fips": "12115",
"apn": "0283080001",
"apnOrig": "0283080001"
},
"lot": {
"lotSize1": 0.837
},
"address": {
"country": "US",
"countrySubd": "FL",
"line1": "7580 PRESERVATION DR",
"line2": "SARASOTA, FL 34241",
"locality": "Sarasota",
"matchCode": "ExaStr",
"oneLine": "7580 PRESERVATION DR, SARASOTA, FL 34241",
"postal1": "34241",
"postal2": "5201",
"postal3": "R038"
},
"location": {
"accuracy": "Street",
"elevation": 0,
"latitude": "27.267342",
"longitude": "-82.419812",
"distance": 0,
"geoid": "MT30003379,RS0000548079,SD67554,SS156496,SS156498,SS190868"
},
"summary": {
"propclass": "Single Family Residence / Townhouse",
"propsubtype": "SINGLE FAMILY",
"proptype": "SFR",
"yearbuilt": 2005,
"propLandUse": "SFR"
},
"building": {
"size": {
"universalsize": 4256
},
"rooms": {
"bathstotal": 5,
"beds": 4
}
},
"vintage": {
"lastModified": "2015-9-11",
"pubDate": "2015-10-7"
},
"salehistory": [
{
"salesearchdate": "2009-3-30",
"saleTransDate": "2009-3-30",
"amount": {
"saleamt": 1250000,
"salerecdate": "2009-3-30",
"saledisclosuretype": 0,
"saledocnum": "37737",
"saletranstype": "Resale"
},
"calculation": {
"priceperbed": 312500,
"pricepersizeunit": 294
}
},
{
"salesearchdate": "2005-8-9",
"saleTransDate": "2005-8-9",
"amount": {
"saleamt": 185000,
"salerecdate": "2005-8-15",
"saledisclosuretype": 0,
"saledocnum": "181999",
"saletranstype": "Resale"
},
"calculation": {
"priceperbed": 46250,
"pricepersizeunit": 43
}
}
]
}
]
}
Actually I was able to get it figured out.
Since it was a nested object within the property object I need to do the following to access it.
response.write oJSON.data("property").item(0).item("salehistory").item(0).item("amount").item("saleamt"
Adding .item(0) after sales history allowed me to access the salehistory object