Working with JSON

MathStudio can parse JSON data into an object by using the json function or using the http function to parse JSON data from a URL.

Examples


Parse a JSON string using the JSON function

weather = json('{"coord":{"lon":-0.13, "lat":51.51}, "sys":{"message":0.066, "country":"GB", "sunrise":1403149363, "sunset":1403209271}, "weather":[{"id":800, "main":"Clear", "description":"Sky is Clear", "icon":"01n"}], "base":"cmc stations", "main":{"temp":289.13, "humidity":63, "pressure":1026, "temp_min":287.59, "temp_max":290.37}, "wind":{"speed":4.03, "deg":46.0037}, "clouds":{"all":0}, "dt":1403210284, "id":2643743, "name":"London", "cod":200}')

Parse a JSON string using the JSON function with a filter

weather = json('{"coord":{"lon":-0.13, "lat":51.51}, "sys":{"message":0.066, "country":"GB", "sunrise":1403149363, "sunset":1403209271}, "weather":[{"id":800, "main":"Clear", "description":"Sky is Clear", "icon":"01n"}], "base":"cmc stations", "main":{"temp":289.13, "humidity":63, "pressure":1026, "temp_min":287.59, "temp_max":290.37}, "wind":{"speed":4.03, "deg":46.0037}, "clouds":{"all":0}, "dt":1403210284, "id":2643743, "name":"London", "cod":200}', filter=[temp, humidity])

Convert a temperature from the JSON data

weather(main, temp)@K -> @F

Plot the stock price of Apple using the HTTP function

// Stock symbol for Apple symbol = "AAPL" // Date for 3 months ago startDate = date("y-0m-0d", -3@months) // The "<<" operator is used for string concatenation url = "query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.historicaldata where symbol='" << symbol << "' and startDate='" << startDate << "' and endDate='today'&format=json&diagnostics=true&env=http://datatables.org/alltables.env" stocks = http(url, filter=[Close, Date])
prices = stocks(query, results, quote, *, Close) round(prices)
dates = date("m/d", stocks(query, results, quote, *, Date))
// Plot the stock price of AAPL ListPlot(prices, labels=dates, width=700, height=220, flipAxis=1)

References

http://json.org

Related Functions

http, json
Using MathStudio
The Basics
1. Introduction
2. Trigonometric Functions
3. Special Values
4. Lists
5. Matrices
6. Algebra
7. Calculus
8. Fourier Analysis
9. Units
10. Base Conversions
11. Regression Analysis
12. Natural Language
13. Constants
14. Dynamic Variables
Operators
1. Basic Operators
2. Double Power Operator
3. Comparison Operators
4. Logical Operators
5. Compound Assignment Operators
6. Type Comparison Operators
7. Size Operator
8. Range Operator
9. Transformation Operator
10. Index Operator
11. Union Operator
12. Intersection Operator
13. Difference Operator
14. Double Modulo Operator
15. Matrix Operator
16. Matrix Size Operator
17. Angle Operator
18. Choose Operator
19. String Concatenation Operator
20. Conditional Operator
21. Append Operator
22. Element Operator
Graphing
1. 2D Graphing
2. Plot Styles
3. Min, Max and Zero Values
4. 3D Graphing
5. Multiple Plots
6. Color Names
7. Time Graphing
Scripting Language
Variables
1. Creating Variables
2. Unicode Characters
3. Variable Functions
4. Strings
5. Wildcards
Scripts
1. Creating Scripts
2. Semicolons
3. Comments
4. Variable Controls
5. Conditional Statements
6. For-In Loops
7. While Loops
8. Timing
9. Objects
10. Working with JSON
Functions
A
abs(z)
AiryAi(z)
AiryBi(z)
AlternatingSeries(n, [terms])
Angle(A, B)
Animate(variable, start, end, [step], [value], [fps])
Apart(f(x), x)
Append(expression1, expression2)
Arg(z)
B
BarPlot(list1, frequency1, ...)
Bernoulli(n, [z])
BesselI(v, z)
BesselJ(v, z)
BesselK(v, z)
BesselY(v, z)
Beta(m, n)
Binomial(n, r)
BinomialCDF(n, p, x)
BinomialPDF(n, p, x)
BodePlot(function, variable, minimum, maximum, mode)
BoxPlot(x, [frequency1], [x2], [frequency2], ...)
Button(name, [list], [value])
C
Call(function, parameter1, parameter2, ...)
Caps(string, index, [mode])
Catalan(n)
Ceil(z)
cFrac(n, [terms])
Char(x)
ChebyshevT(n, z)
ChebyshevU(n, z)
CheckBox(variable, [value])
Chi(z)
ChiSquareCDF(lower, upper, df)
ChiSquarePDF(x, df)
Cholesky(A)
Choose(test1, value1, test2, value2, ...)
Ci(z)
Clear(variable, ...)
clip(x, [min], [max])
Coefficient(f(x), x, degree)
coFactor(matrix, i, j)
Command(setting)
Conj(z)
ContourPlot(expression, ...)
Convergents(n, [mode=0], [terms])
Cross(A, B)
CubicFit([x], y)
CubicFitModel([x], y)
CubicFitPlot([x], y)
Curl(vector, [varlist], [mode])
CylindricalPlot3D(expression, ...)
D
D(f(x), x, [n])
Date(letter)
Dawson(z)
Degree(expression)
DEGtoDMS(angle, [digits])
Delete(expression, position, [length])
Denominator(expression)
Det(A)
Diff(f(x), x)
DiGamma(z)
DiLog(z)
Dirichlet_Eta(z)
Dirichlet_Lambda(z)
Divergence([varlist], vector, [mode])
Divisors(n)
DivisorSigma(n)
Dot(A, B)
DSolve(equation, dependent(independent), values, mode=1)
Duf(function, [varlist], [point], [direction])
dynamic(name, value)
E
Ei(z)
Eigenvalues(A)
Eigenvectors(A)
Else If(condition)
Erf(z)
Erfc(z)
Error(string)
Euler(n, [z])
Eulerian(n, k)
Eval(function, variable, value)
Exp(z)
Expand(expression)
ExpConvert(expression)
ExpFit([x], y)
ExpFitModel([x], y)
ExpFitPlot([x], y)
ExponentialFit([x], y)
ExponentialFitModel([x], y)
ExponentialFitPlot([x], y)
Extract(expression, position, [length])
F
Factor(expression)
Factorial(n)
Fcdf(lower, upperbound, numerator, denominator)
fDiff(f(x,y,z,..), (x,y,z,...))
Fibonacci(n, [z])
Finance(PV, FV, Pmt, i, n, [mode=0])
FindFit(function, variable, [x], y)
FindFitModel(function, variable, [x], y)
FindFitPlot(function, variable, [x], y)
Flatten(matrix)
Floor(z)
FourierCos(f(x), x, w)
FourierExpSeries(f(x), x, n)
FourierSeries(f(x), x, [n], [mode])
FourierSin(f(x), x, w)
FourierTrigSeries(f(x), x, n)
fPart(z)
Fpdf(x, d1, d2)
FractalPlot(expression, ...)
FresnelCos(z)
FresnelSin(z)
FullRectSineWave(x, [T])
Function(function, parameter1, parameter2, ...)
G
Gamma(z)
GCD(n1, n2)
GegenbauerC(n, a, z)
GeoCDF(p, x)
GeoPDF(p, x)
Gradient(function, [varlist], [mode])
Gudermannian(z)
H
HalfRectSineWave(x, [T])
HankelH1(v, z)
HankelH2(v, z)
Harmonic(z)
Heaviside(x)
HermiteH(n, z)
Hessian(function, [varlist], [mode])
HRStoHMS(hours, [digits])
http(url, [filter])
Hypergeom_2F1(a, b, c, z, [mode])
I
Identity(n)
iDiff(f(x,y,z,..), dependant_variables, independant_variables)
If(condition)
iLaplace(F(s), s)
Im(z)
ImagePlot(data)
ImaginaryPart(expression)
ImplicitPlot(expression, ...)
Include(filename)
Insert(expression, item, position)
Integrate(f(x), x, [a], [b])
Inverse(A)
InverseNormal(p, [mu], [sigma])
invGudermannian(z)
iPart(z)
IsList(expression)
IsMatrix(expression)
IsNumber(expression)
IsPoly(expression, variable)
IsPrime(n)
J
Jacobian(function, [varlist], [point])
json(data, [filter])
JuliaPlot(expression, ...)
K
KelvinBei(v, z)
KelvinBer(v, z)
KelvinKei(v, z)
KelvinKer(v, z)
L
LaguerreL(n, z)
LambertW(z)
Laplace(f(t), t)
Laplacian(function, [varlist], [mode])
LCM(n1, n2)
Left(expression)
LegendreP(n, z)
LegendreQ(n, z)
Length(expression)
Li(x)
Limit(function, variable, point, [direction])
LinearFit([x], y)
LinearFitModel([x], y)
LinearFitPlot([x], y)
List(length)
ListMap(list, name, [value])
ListPlot(x, [y], [x2], [y2])
ListPlot3D(x, y, z, [x2], [y2], [z2], ...)
Ln(z)
LnFit([x], y)
LnFitModel([x], y)
LnFitPlot([x], y)
LnGamma(z)
local(name, value)
Log([n], z)
LogisticFit([x], y)
LogisticFitModel([x], y)
LogisticFitPlot([x], y)
Lucas(n, [z])
M
Matrix(rows, [columns])
MatrixLU(matrix, [mode])
MatrixMap(matrix, name, [value])
MatrixQR(A)
MatrixSVD(A)
Max(number, ...)
Mean(list)
MedianFit([x], y)
MedianFitModel([x], y)
MedianFitPlot([x], y)
Message(string)
Min(list)
Mod(m, n)
Multinomial(nList)
MultiPlot(plot1, plot2, ...)
MultiPlot3D(expression, ...)
N
nCr(n, r)
NIntegrate(f(x), x, a, b)
Norm(z)
NormalCDF(lower, upper, [mu], [sigma])
NormalPDF(x, mu, sigma)
nPr(n, r)
nPrimes(n)
nRoot(z, n, [mode])
P
ParametricPlot(expression, ...)
ParametricPlot3D(expression, ...)
Part(expression, n)
pDiff(f(x,y,z,..), dependent_variables, dependent_equations, independent_variables)
Pi_Digits(n)
Plot(expression, ...)
Plot3D(expression, ...)
Pochhammer(n, k)
PoissonCDF(mu, x)
PoissonPDF(mu, x)
PolarPlot(expression, ...)
PolyDivide(f(z), g(z))
PolyFit(pList, var)
PolyGamma(n, z)
PolyGCD(polynomial1, polynomial2)
PolyLCM(polynomial1, polynomial2, [mode=1])
PolyLog(n, z)
PowerExpand(expression)
PowerFit([x], y)
PowerFitModel([x], y)
PowerFitPlot([x], y)
Prime(n)
Primorial(n)
Product(f(n), n, start, end)
Psi(z)
Q
QuadraticFit([x], y)
QuadraticFitModel([x], y)
QuadraticFitPlot([x], y)
QuarticFit([x], y)
QuarticFitModel([x], y)
QuarticFitPlot([x], y)
Quotient(f(x), g(x))
R
Random(min, max, [size1], [size2])
Re(z)
RealPart(expression)
Remainder(f(x), g(x))
Replace(expression, old, new)
Reshape(matrix)
Return(expression)
Reverse(list)
Right(expression)
RK4(function, t, y, a, b, y0, N=10)
RK45(function, t, y, a, b, y0, Tol=10E-5, hmax=0.25, hmin=10E-6, N=20)
Round(number, digits)
RowReduce(A)
S
SawToothWave(x, [T])
Sequence(f(x), x, start, end, [step], [start term], [number of terms])
Series(f(z), z, n)
Shi(z)
Si(z)
Sign(z)
SimplifyFunction(expression)
SimplifyPoly(f(x)/g(x), [variable])
sin(z)
SinFit([x], y)
SinFitModel([x], y)
SinFitPlot([x], y)
Size(list)
Slider(variable, start, end, [step], [initial value])
Solve(f(x), x, [guess])
SolveSystem(equations, [variables], [guesses])
Sort(list)
SphericalPlot3D(expression, ...)
Sqrt(z)
SquareWave(x, [T])
StaircaseWave(x, [T])
StandardDeviation(list)
String(expression1, expression2, ...)
StudentTCDF(x, df)
StudentTPDF(x, df)
Sum(f(n), n, start, end)
SurfaceNormal(function, [varlist], [point])
T
Together(expression)
Trace(variable)
Transpose(A)
TriangleWave(x, [T])
TrigConvert(expression)
TrigExpand(expression)
TrigReduce(expression)
V
Variables(expression)
Variance(list)
VectorPlot(list, ...)
VectorPlot3D(list, ...)
W
While(condition)
Z
Zeta(z, [a])