Ways to store JSON data - json

I'm making an API call and the response I'm getting is a rather large JSON string. I'd like to minimise API calls to a) avoid hitting the rate limit and b) speed things up.
Here's an example of my JSON data:
{
"firstName": "John",
"lastName": "Smith",
"isAlive": true,
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "office",
"number": "646 555-4567"
}
],
"children": [],
"spouse": null
}
My question:
What are my options with reference to persistent storage?
Please note: the API I'm using is in beta; so I'd like to avoid using MySQL for now because the JSON representation could change, resulting in my tables needing an overhaul.

Related

Convert a JSON array into a solidity mapping in a chainlink node external adapter?

I have a custom external adapter runnning on a chainlink node. When the adapter is triggered, it gets a response from an api that sends back a json object with a list of objects. I want to covert the array in this json object into a solidity mapping for my smart contract.
For example could I get the property "array of objects" from this response and convert it into a solidity mapping for my client contract to use?
"random": 89,
"random float": 10.669,
"bool": true,
"date": "1980-11-24",
"regEx": "helloooooooooooooooooooooo to you",
"enum": "json",
"firstname": "Stevana",
"lastname": "Killigrew",
"city": "Port Moresby",
"country": "Isle of Man",
"countryCode": "PY",
"email uses current data": "Stevana.Killigrew#gmail.com",
"email from expression": "Stevana.Killigrew#yopmail.com",
"array": [
"Vanessa",
"Chloris",
"Glynnis",
"Fidelia",
"Kaja"
],
"array of objects": [
{
"index": 0,
"index start at 5": 5,
"team": "na",
"company": "CVS",
"department": "hair and beauty"
},
{
"index": 1,
"index start at 5": 6,
"team": "na",
"company": "CVS",
"department": "hair and beauty"
},
{
"index": 2,
"index start at 5": 7,
"team": "na",
"company": "CVS",
"department": "hair and beauty"
}
],
"Ronna": {
"age": 82
}
}```
One can't get an "array of objects" at the moment from the external adapter, here is the list of currently supported response types.
You will need to make a Multi-Varibale Responses request and then get each individual property like this

Jmeter: JSON response manipulation and passing to the next http request

I've got the response from HTTP GET request as JSON file and I want to use that JSON and pass it to the next HTTP request. I got the following response data
{
"apiInfo": {
"id": "23143",
"name": "bookkeeping",
"state": "used",
"data": "15893712000000"
},
"apiDetails": [
{
"bookName": "abc",
"state": "old",
"noOfTimesUsed": "53"
"additionalParam"{
"name": "abc",
"id": "123"
}
},
{
"bookName": "def",
"state": "new",
"noOfTimesUsed": "5",
"action": "keep"
"additionalParam"{
"name": "def",
"id": "456"
}
},
{
"bookName": "xyz",
"state": "avg",
"noOfTimesUsed": "23"
"additionalParam"{
"name": "ghi",
"id": "789"
}
},
{
"bookName": "pqr",
"state": "old",
"noOfTimesUsed": "75",
"action": "discard"
"additionalParam"{
"name": "jkl",
"id": "012"
}
}
]
}
I want to use "apiInfo" & "apiDetails" part from the JSON response and manipulate its data. As you can notice, some array field have attribute "action" in it and some one doesn't. I want to make sure all the field in the array have this data and is assigned as ' "action":"keep" '. Also, I want to add "id" from apiInfo & "name" from additionalParams from apiDetails itself. The end result I want is somewhat like this
"apiDetails": [
{
"id": "23143",
"bookName": "abc",
"state": "old",
"noOfTimesUsed": "53",
"action": "keep",
"name":"abc"
},
{
"id": "23143",
"bookName": "def",
"state": "new",
"noOfTimesUsed": "5",
"action": "keep",
"name":"def"
},
{
"id": "23143",
"bookName": "xyz",
"state": "avg",
"noOfTimesUsed": "23",
"action": "keep",
"name":"ghi"
},
{
"id": "23143",
"bookName": "pqr",
"state": "old",
"noOfTimesUsed": "75",
"action": "keep",
"name":"jkl"
}
]
I've been trying to use JSR223 sampler and have been struggling with it. It's bit complicated and I need help. P.S.: I've tried using javascript code to manipulate the results as desired but have been unsuccessful.
Please help.
Thanks, Sid
Add JSR223 PostProcessor as a child of the request which returns the above JSON
Put the following code into "Script" area:
def apiDetails = new groovy.json.JsonSlurper().parse(prev.getResponseData()).apiDetails
apiDetails.each { apiDetail ->
apiDetail.put('action', 'keep')
}
vars.put('request', new groovy.json.JsonBuilder(apidetails: apiDetails.collect()).toPrettyString())
That's it, you should be able to refer the generated request as ${request} where required
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It

Structure data inside a Document database

I'm building a app that is going to serve as an agenda or a scheduling book for some services. It's planned to the app to work in a "per customer" way, Angular in the front-end and to use the new Google Firestore, for all the real time and pseudo-backendless stuff.
The question is, as I have never worked with NoSQL databases before, how should I structure the data inside Firestore?
I thought about something that would look like this:
{
//Collection
"customer-a": {
//Document
"info": {
"name": "Customer A",
"Phones": [{
"contact-name": "",
"number": ""
}],
"address": {
"type": "street",
"name": "",
"number": 0,
"neighborhood": "",
"city": "",
"state": "",
"zipcode": "",
"country": "",
"coordinates": {
"latitude": "",
"longitude": ""
}
}
},
//Document
"config": {
"active-theme": "",
"themes": [{}]
},
//Document
"customer-data": {
//SubCollection
"employees": {
//Document
"employee-a": {
"name": "",
"phone": "",
"rattings": [],
"address": {
"type": "street",
"name": "",
"number": 0,
"neighborhood": "",
"city": "",
"state": "",
"zipcode": "",
"country": ""
},
//SubCollection
"schedulings": {
//Document
"2017": {
"total": 300,
"scheduling": [{
"client": {
"name": "",
"phone": "",
"rating": 5,
},
"price": 10,
"services": [{
"name": "",
"price": 10
}],
"datetime": "",
}]
},
"2018": {
"total": 300,
"scheduling": [{
"client": {
"name": "",
"phone": "",
"classificacao": 5,
},
"price": 10,
"services": [{
"name": "",
"price": 10
}],
"datetime": "",
}]
},
}
}
},
//SubCollection
"stock": {}
}
}
}
I'm thinking on splitting the scheduling into years because I think it may grow in size a lot, but as I said, I've never worked with this kind of database, so I don't really know how much data I could nest inside a document, for example...
As an exaggerated amount of data for a base calculation I thought about around 200k "objects" that would be stored for each employee per year, is that much or it's ok to store that much data nested?
Should I keep creating sub collections inside Firestore or it should be one single collections to store only different documents and nest everything?
Hope someone can help me,
Thanks.

fetch data from json file in Polymer

I have a json file like below
{
"23": {
"id": 23,
"featured": true,
"name": "Dawid Ostrowski",
"title": "Developer Relations Program Manager",
"company": "Google",
"country": "Switzerland",
"photoUrl": "/images/people/dawid_ostrowski.jpg",
},
"9": {
"id": 9,
"featured": true,
"name": "Mandy Waite",
"title": "Developer Relations Engineer",
"company": "Google",
"country": "UK",
},
"15": {
"id": 15,
"featured": true,
"name": "Jakub Škvára",
"title": "Frontend engineer",
"company": "Shipito",
"country": "Czech Republic",
"photoUrl": "/images/people/jakub_skvara.jpg",
},
"14": {
"id": 14,
"name": "Jana Moudrá",
"title": "Co-Founder",
"company": "Juicymo",
"country": "Czech Republic",
"photoUrl": "/images/people/jana_moudra.jpg"
}
}
I want to get all data of a specific id in Polymer.
like if someone visit example.com/user/23, I want to get the data of 23 so I can display a page using the data.
How do i do it in Polymer?
Assuming you just have one static .json file, and not an API to selectively return JSON strings based on query parameters, you could do the following.
Implement the following method on your Polymer element:
getEntryById: function (id) {
return this.queryResult[id];
}
Use Polymer's iron-ajax element and bind the lastResponse property of this element to queryResult on your new element, and the requestUrl property to the location of your .json file.
Of course, you need some kind of client-side router (like Page.js, included in Polymer Starter Kit) that reads the route and route parameters (the user Id) from the URL and passes it to your Polymer element, so you can appropriately call the getEntryById function.

Is it possible to get multiple user checkins from the Foursquare Real-Time API

What my overall aim is to have check-ins from a group of friends be displayed (most recent first) on a private web-app I am building.
Is this possible?
And if so, could someone kindly lead me in the right direction.
Thank you in advance :)
As long as they oAuth your application, you should be able to do this. You can't do this unless they explicitly allow you to for obvious security reasons. If you want a way around that, you can web scrape, but that is another issue entirely.
Take a look at their Real-Time API: https://developer.foursquare.com/overview/realtime
Create an application, then utilize their User Push API - every time one of them checks in, it should push something like this to your server:
{
"id": "4e6fe1404b90c00032eeac34",
"createdAt": 1315955008,
"type": "checkin",
"timeZone": "America/New_York",
"user": {
"id": "1",
"firstName": "Jimmy",
"lastName": "Foursquare",
"photo": "https://foursquare.com/img/blank_boy.png",
"gender": "male",
"homeCity": "New York, NY",
"relationship": "self"
},
"venue": {
"id": "4ab7e57cf964a5205f7b20e3",
"name": "foursquare HQ",
"contact": {
"twitter": "foursquare"
},
"location": {
"address": "East Village",
"lat": 40.72809214560253,
"lng": -73.99112284183502,
"city": "New York",
"state": "NY",
"postalCode": "10003",
"country": "USA"
},
"categories": [
{
"id": "4bf58dd8d48988d125941735",
"name": "Tech Startup",
"pluralName": "Tech Startups",
"shortName": "Tech Startup",
"icon": "https://foursquare.com/img/categories/building/default.png",
"parents": [
"Professional & Other Places",
"Offices"
],
"primary": true
}
],
"verified": true,
"stats": {
"checkinsCount": 7313,
"usersCount": 565,
"tipCount": 128
},
"url": "http://foursquare.com"
}
}
Best of luck to you!