I tried searching but couldn't find any proper solution for this. I am trying to parse JSON using the RestClient gem in Ruby without a root key. When I parse it, it returns blank values.
This is the sample JSON I am trying to parse.
[
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere#april.biz",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
}
},
{
"id": 2,
"name": "Ervin Howell",
"username": "Antonette",
"email": "Shanna#melissa.tv",
"address": {
"street": "Victor Plains",
"suite": "Suite 879",
"city": "Wisokyburgh",
"zipcode": "90566-7771",
"geo": {
"lat": "-43.9509",
"lng": "-34.4618"
}
},
"phone": "010-692-6593 x09125",
"website": "anastasia.net",
"company": {
"name": "Deckow-Crist",
"catchPhrase": "Proactive didactic contingency",
"bs": "synergize scalable supply-chains"
}
}
]
I get the proper output, but when I try to access specific fields, I get blank output:
require 'rest-client'
output = RestClient.get 'https://jsonplaceholder.typicode.com/users'
puts output
puts output[0]["username"]
I get no output for username.
rest-client does not parse the JSON itself. You need to do this as an explicit step:
require 'rest-client'
response = RestClient.get('https://jsonplaceholder.typicode.com/users')
output = JSON.parse(response.body) # or just JSON.parse(response) would also work
puts output[0]["username"]
Related
Have below code to generate page result to get below expected result but i am getting below current result. Client using this end point is breaking as there are no items,nextpagelink and count available after upgrading the framework to net6 and odata to 8.0.11
Expected Result :
{
"items": [
{"id":6975,"name":"Dummy Value","phone":"999999999","fax":null,"address":"Dummy street","city":"Some","state":"some","zipCode":"99999","countryId":1}],
"nextPageLink":"/Vendors?$filter=zipCode%20eq%20%2785022%27&$orderby=name%20asc&$skip=50",
"count":null
}
Current Result :
{
"#odata.context": "http://localhost:8080/$metadata#Vendors",
"value":
[
{
"id": 6975,
"name": "Dummy Value",
"phone": "999999999",
"fax": null,
"address": "Dummy",
"city": "Some",
"state": "Some",
"zipCode": "99999",
"countryId": 1
}
],
"#odata.nextLink": "/Vendors?$filter=zipCode%20eq%20%2799999%27&$orderby=name%20asc&$skip=50"
Controller Code:
Start up.cs :
Expected Result :
{
"items": [
{"id":6975,"name":"Dummy Value","phone":"999999999","fax":null,"address":"Dummy street","city":"Some","state":"some","zipCode":"99999","countryId":1}],
"nextPageLink":"/Vendors?$filter=zipCode%20eq%20%2785022%27&$orderby=name%20asc&$skip=50",
"count":null
}
Current Result :
{
"#odata.context": "http://localhost:8080/$metadata#Vendors",
"value":
[
{
"id": 6975,
"name": "Dummy Value",
"phone": "999999999",
"fax": null,
"address": "Dummy",
"city": "Some",
"state": "Some",
"zipCode": "99999",
"countryId": 1
}
],
"#odata.nextLink": "/Vendors?$filter=zipCode%20eq%20%2799999%27&$orderby=name%20asc&$skip=50"
I'm very new to OpenAPI and I'm using http://editor.swagger.io to design an API.
I'm stuck in Schema with a JSON looking like following
{
"CORRELATION_ID": "10",
"CONTROL":
{
"DAS_IS_RECIPIENT": "123",
"DOCTPYE": "ert",
"PROCESS_INDICATOR": "nord"
},
"HEADER":
{
"ID": "456",
"INVOICE_NUMBER": "678",
"DMS_DOC_ID": "876",
"INVOICE_DATE": "10082020"
},
"ITEMS": [
{
"SHORT_TEXT": "123",
"LSTAR": 0,
"QUANTITY": "23"
},
{
"SHORT_TEXT": "456",
"LSTAR": 234,
"QUANTITY": "21"
}
],
"DEBITOR":
{
"ID": "444",
"FIRSTNAME": "nick",
"LASTNAME": "cantre"
},
"CREDITOR":
{
"ID": "454",
"FIRSTNAME": "ava",
"LASTNAME": "pierre"
}
}
How to create a schema according to this JSON structure?
It appears there is still no way to import JSON or CSV files directly to a Firestore database. Many of the suggestions are for JavaScript-based apps that do not translate well to Swift. Does anyone have a good Swift solution for adding data to a Firestore database using JSON/CSV?
//example json
[
{
"name": "Stone Cove Marina Inc",
"email": "NOT IN SAMPLE",
"category": "Docks",
"category2": "Marinas",
"category3": "Dock Builders",
"address": "134 Salt Pond Rd",
"city": "Wakefield",
"state": "RI",
"zip": 2879,
"phone": "(401) 783-8990",
"website": "http://stonecovemarinari.com"
},
{
"name": "Bluehaven Homes",
"email": "NOT IN SAMPLE",
"category": "General Contractors",
"category2": "Home Builders",
"category3": "",
"address": "5701 Time Sq",
"city": "Amarillo",
"state": "TX",
"zip": 79119,
"phone": "(806) 452-2545",
"website": "http://www.bluehavenhomes.com/"
}
]
//here is the database structure
//collection is "businesses"; each "business" gets a document id; within each document id set the data
database.collection("businesses").document().setData(/*data here*/)
You can try
let str = """
[
{
"name": "Stone Cove Marina Inc",
"email": "NOT IN SAMPLE",
"category": "Docks",
"category2": "Marinas",
"category3": "Dock Builders",
"address": "134 Salt Pond Rd",
"city": "Wakefield",
"state": "RI",
"zip": 2879,
"phone": "(401) 783-8990",
"website": "http://stonecovemarinari.com"
},
{
"name": "Bluehaven Homes",
"email": "NOT IN SAMPLE",
"category": "General Contractors",
"category2": "Home Builders",
"category3": "",
"address": "5701 Time Sq",
"city": "Amarillo",
"state": "TX",
"zip": 79119,
"phone": "(806) 452-2545",
"website": "http://www.bluehavenhomes.com/"
}
]
"""
do {
let json = try JSONSerialization.jsonObject(with:str.data(using:.utf8)!, options: []) as! [[String: Any]]
for var i in 0...json.count - 1
{
database.collection("businesses").document().setData(json[i])
}
} catch {
print(error)
}
I'm doing an integration of mobile app with the Office 365 Calendar. I want to show room capacity and location on the screen. I trying to find an API to get meeting room info (this info is available on website when selecting room as user).
I tried both Outlook REST API (version 2.0) and Microsoft Graph but found nothing in the docs on how to get such info.
Where I can find such API if it exists?
I know this is an old question but you can do it using the List Places API in Graph API: https://learn.microsoft.com/en-us/graph/api/place-list?view=graph-rest-1.0&tabs=http
GET https://graph.microsoft.com/v1.0/places/microsoft.graph.room
RESPONSE:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#places/microsoft.graph.room",
"value": [
{
"id": "3162F1E1-C4C0-604B-51D8-91DA78989EB1",
"emailAddress": "cf100#contoso.com",
"displayName": "Conf Room 100",
"address": {
"street": "4567 Main Street",
"city": "Buffalo",
"state": "NY",
"postalCode": "98052",
"countryOrRegion": "USA"
},
"geoCoordinates": {
"latitude": 47.640568390488626,
"longitude": -122.1293731033803
},
"phone": "000-000-0000",
"nickname": "Conf Room",
"label": "100",
"capacity": 50,
"building": "1",
"floorNumber": 1,
"isManaged": true,
"isWheelChairAccessible": false,
"bookingType": "standard",
"tags": [
"bean bags"
],
"audioDeviceName": null,
"videoDeviceName": null,
"displayDevice": "surface hub"
},
{
"id": "3162F1E1-C4C0-604B-51D8-91DA78970B97",
"emailAddress": "cf200#contoso.com",
"displayName": "Conf Room 200",
"address": {
"street": "4567 Main Street",
"city": "Buffalo",
"state": "NY",
"postalCode": "98052",
"countryOrRegion": "USA"
},
"geoCoordinates": {
"latitude": 47.640568390488625,
"longitude": -122.1293731033802
},
"phone": "000-000-0000",
"nickname": "Conf Room",
"label": "200",
"capacity": 40,
"building": "2",
"floorNumber": 2,
"isManaged": true,
"isWheelChairAccessible": false,
"bookingType": "standard",
"tags": [
"benches",
"nice view"
],
"audioDeviceName": null,
"videoDeviceName": null,
"displayDevice": "surface hub"
}
]
}
If I pass a BSON::OrderedHash (from a MongoDb collection) to JSON.pretty_generate I get the json document but unformatted. How can I get a bson document formatted like .pretty() does?
It works for me with mongo 1.9.1, bson 1.9.1, and json 1.8.0 as shown in the following test code, as close as can be expected.
pretty_bson.rb
require 'mongo'
require 'bson'
require 'json'
require 'test/unit'
class BsonPrettyTest < Test::Unit::TestCase
def setup
#client = Mongo::MongoClient.new
#db = #client['test']
#coll = #db['people']
#coll.remove
assert_equal 0, #coll.count
end
test "bson pretty" do
text = <<-EOF
{
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": 10021
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "fax",
"number": "646 555-4567"
}
]
}
EOF
hash = JSON.parse(text)
#coll.insert(hash)
doc = #coll.find_one
assert_equal BSON::OrderedHash, doc.class
puts JSON.pretty_generate(hash)
puts JSON.pretty_generate(doc)
end
end
ruby pretty_bson.rb
Loaded suite pretty_bson
Started
{
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": 10021
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "fax",
"number": "646 555-4567"
}
],
"_id": {"$oid": "51df0c537f11bab55d000001"}
}
{
"_id": {"$oid": "51df0c537f11bab55d000001"},
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": 10021
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "fax",
"number": "646 555-4567"
}
]
}
.
Finished in 0.005689 seconds.
1 tests, 2 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
175.78 tests/s, 351.56 assertions/s