DennisVDB DennisVDB - 3 months ago 9
JSON Question

ValidationError (path missing) in Play Json

I have the

Json
string:
[{"cid":"1039420885783365","name":"","s":"TSLA160916C00005000","e":"OPRA","p":"219.64","cs":"chb","c":"0.00","cp":"0.00","b":"190.30","a":"194.85","oi":"2","vol":"-","strike":"5.00","expiry":"Sep 16, 2016"}, ... ]


My code:

case class OptionEntry(cid: String,
name: String,
s: String,
e: String,
p: String,
cs: String,
c: String,
cp: String,
b: String,
a: String,
oi: String,
vol: String,
strike: String,
expiry: String)

val optionEntries = Json.parse(jsonString)

implicit val optionEntryReads: Reads[OptionEntry] = (
(JsPath \ "cid").read[String] and
(JsPath \ "name").read[String] and
(JsPath \ "s").read[String] and
(JsPath \ "e").read[String] and
(JsPath \ "p").read[String] and
(JsPath \ "cs").read[String] and
(JsPath \ "c").read[String] and
(JsPath \ "cp").read[String] and
(JsPath \ "b").read[String] and
(JsPath \ "a").read[String] and
(JsPath \ "oi").read[String] and
(JsPath \ "vol").read[String] and
(JsPath \ "strike").read[String] and
(JsPath \ "expiry").read[String]
)(OptionEntry.apply _)

println(optionEntries.validate[List[OptionEntry]])


The Json string:

[{"cid":"1039420885783365","name":"","s":"TSLA160916C00005000","e":"OPRA","p":"219.64","cs":"chb","c":"0.00","cp":"0.00","b":"194.70","a":"197.90","oi":"2","vol":"-","strike":"5.00","expiry":"Sep 16, 2016"},{"cid":"259816193292639","name":"","s":"TSLA160916C00010000","e":"OPRA","p":"182.50","cs":"chb","c":"0.00","cp":"0.00","b":"189.85","a":"192.75","oi":"0","vol":"-","strike":"10.00","expiry":"Sep 16, 2016"},{"cid":"834521657091252","name":"","s":"TSLA160916C00015000","e":"OPRA","p":"211.09","cs":"chb","c":"0.00","cp":"0.00","b":"184.80","a":"187.20","oi":"1","vol":"-","strike":"15.00","expiry":"Sep 16, 2016"},{"cid":"58038573817889","name":"","s":"TSLA160916C00020000","e":"OPRA","p":"206.06","cs":"chb","c":"0.00","cp":"0.00","b":"179.70","a":"182.20","oi":"1","vol":"-","strike":"20.00","expiry":"Sep 16, 2016"},{"cid":"400783271986149","name":"","s":"TSLA160916C00025000","e":"OPRA","p":"151.58","cs":"chb","c":"0.00","cp":"0.00","b":"174.85","a":"177.70","oi":"0","vol":"-","strike":"25.00","expiry":"Sep 16, 2016"},{"cid":"397108163551042","name":"","s":"TSLA160916C00030000","e":"OPRA","p":"-","c":"-","b":"169.85","a":"172.70","oi":"0","vol":"-","strike":"30.00","expiry":"Sep 16, 2016"},{"cid":"39807976369121","name":"","s":"TSLA160916C00035000","e":"OPRA","p":"-","c":"-","b":"164.70","a":"167.70","oi":"0","vol":"-","strike":"35.00","expiry":"Sep 16, 2016"},{"cid":"162843593973912","name":"","s":"TSLA160916C00040000","e":"OPRA","p":"186.17","cs":"chb","c":"0.00","cp":"0.00","b":"159.85","a":"162.25","oi":"1","vol":"-","strike":"40.00","expiry":"Sep 16, 2016"},{"cid":"105072414761672","name":"","s":"TSLA160916C00045000","e":"OPRA","p":"208.10","cs":"chb","c":"0.00","cp":"0.00","b":"154.85","a":"157.75","oi":"1","vol":"-","strike":"45.00","expiry":"Sep 16, 2016"},{"cid":"839642082077864","name":"","s":"TSLA160916C00050000","e":"OPRA","p":"158.00","cs":"chb","c":"0.00","cp":"0.00","b":"149.85","a":"152.90","oi":"0","vol":"-","strike":"50.00","expiry":"Sep 16, 2016"},{"cid":"738268109616581","name":"","s":"TSLA160916C00055000","e":"OPRA","p":"171.43","cs":"chb","c":"0.00","cp":"0.00","b":"144.50","a":"147.40","oi":"1","vol":"-","strike":"55.00","expiry":"Sep 16, 2016"},{"cid":"1110347752052358","name":"","s":"TSLA160916C00060000","e":"OPRA","p":"-","c":"-","b":"139.50","a":"142.75","oi":"0","vol":"-","strike":"60.00","expiry":"Sep 16, 2016"},{"cid":"701783145177326","name":"","s":"TSLA160916C00065000","e":"OPRA","p":"-","c":"-","b":"134.50","a":"137.75","oi":"0","vol":"-","strike":"65.00","expiry":"Sep 16, 2016"},{"cid":"654322547204560","name":"","s":"TSLA160916C00070000","e":"OPRA","p":"149.88","cs":"chb","c":"0.00","cp":"0.00","b":"129.70","a":"132.75","oi":"0","vol":"-","strike":"70.00","expiry":"Sep 16, 2016"},{"cid":"741226138508078","name":"","s":"TSLA160916C00075000","e":"OPRA","p":"-","c":"-","b":"124.50","a":"127.75","oi":"0","vol":"-","strike":"75.00","expiry":"Sep 16, 2016"},{"cid":"972168634803798","name":"","s":"TSLA160916C00080000","e":"OPRA","p":"-","c":"-","b":"119.50","a":"122.75","oi":"0","vol":"-","strike":"80.00","expiry":"Sep 16, 2016"},{"cid":"986485863274043","name":"","s":"TSLA160916C00085000","e":"OPRA","p":"-","c":"-","b":"114.50","a":"117.85","oi":"0","vol":"-","strike":"85.00","expiry":"Sep 16, 2016"},{"cid":"1095545768550226","name":"","s":"TSLA160916C00090000","e":"OPRA","p":"138.52","cs":"chb","c":"0.00","cp":"0.00","b":"109.85","a":"112.20","oi":"0","vol":"-","strike":"90.00","expiry":"Sep 16, 2016"},{"cid":"26254300000394","name":"","s":"TSLA160916C00095000","e":"OPRA","p":"127.10","cs":"chb","c":"0.00","cp":"0.00","b":"104.70","a":"107.90","oi":"0","vol":"-","strike":"95.00","expiry":"Sep 16, 2016"},{"cid":"1118117726847457","name":"","s":"TSLA160916C00100000","e":"OPRA","p":"123.27","cs":"chb","c":"0.00","cp":"0.00","b":"99.50","a":"102.15","oi":"13","vol":"-","strike":"100.00","expiry":"Sep 16, 2016"},{"cid":"245141050010264","name":"","s":"TSLA160916C00105000","e":"OPRA","p":"95.29","cs":"chb","c":"0.00","cp":"0.00","b":"94.70","a":"97.90","oi":"0","vol":"-","strike":"105.00","expiry":"Sep 16, 2016"},{"cid":"439847478157007","name":"","s":"TSLA160916C00110000","e":"OPRA","p":"100.90","cs":"chb","c":"0.00","cp":"0.00","b":"89.50","a":"92.20","oi":"0","vol":"-","strike":"110.00","expiry":"Sep 16, 2016"},{"cid":"41101379521672","name":"","s":"TSLA160916C00115000","e":"OPRA","p":"114.53","cs":"chb","c":"0.00","cp":"0.00","b":"84.70","a":"87.20","oi":"0","vol":"-","strike":"115.00","expiry":"Sep 16, 2016"},{"cid":"140943872831911","name":"","s":"TSLA160916C00120000","e":"OPRA","p":"105.36","cs":"chb","c":"0.00","cp":"0.00","b":"79.70","a":"82.90","oi":"0","vol":"-","strike":"120.00","expiry":"Sep 16, 2016"},{"cid":"966450180416270","name":"","s":"TSLA160916C00125000","e":"OPRA","p":"108.00","cs":"chb","c":"0.00","cp":"0.00","b":"74.85","a":"77.20","oi":"0","vol":"-","strike":"125.00","expiry":"Sep 16, 2016"},{"cid":"244268213784819","name":"","s":"TSLA160916C00130000","e":"OPRA","p":"93.40","cs":"chb","c":"0.00","cp":"0.00","b":"69.85","a":"72.30","oi":"11","vol":"-","strike":"130.00","expiry":"Sep 16, 2016"},{"cid":"439803738360712","name":"","s":"TSLA160916C00135000","e":"OPRA","p":"82.23","cs":"chb","c":"0.00","cp":"0.00","b":"64.70","a":"67.80","oi":"1","vol":"-","strike":"135.00","expiry":"Sep 16, 2016"},{"cid":"338143164805850","name":"","s":"TSLA160916C00140000","e":"OPRA","p":"88.79","cs":"chb","c":"0.00","cp":"0.00","b":"59.85","a":"62.85","oi":"1","vol":"-","strike":"140.00","expiry":"Sep 16, 2016"},{"cid":"384979845128979","name":"","s":"TSLA160916C00145000","e":"OPRA","p":"66.55","cs":"chb","c":"0.00","cp":"0.00","b":"54.85","a":"57.20","oi":"4","vol":"-","strike":"145.00","expiry":"Sep 16, 2016"},{"cid":"704065395489746","name":"","s":"TSLA160916C00150000","e":"OPRA","p":"60.00","cs":"chb","c":"0.00","cp":"0.00","b":"49.45","a":"52.20","oi":"21","vol":"-","strike":"150.00","expiry":"Sep 16, 2016"},{"cid":"942910344574849","name":"","s":"TSLA160916C00155000","e":"OPRA","p":"56.00","cs":"chb","c":"0.00","cp":"0.00","b":"44.50","a":"47.20","oi":"28","vol":"-","strike":"155.00","expiry":"Sep 16, 2016"},{"cid":"751610325900763","name":"","s":"TSLA160916C00160000","e":"OPRA","p":"42.00","cs":"chr","c":"-8.50","cp":"-16.83","b":"40.75","a":"41.30","oi":"8","vol":"10","strike":"160.00","expiry":"Sep 16, 2016"},{"cid":"580000290226652","name":"","s":"TSLA160916C00165000","e":"OPRA","p":"45.85","cs":"chb","c":"0.00","cp":"0.00","b":"34.80","a":"38.10","oi":"9","vol":"-","strike":"165.00","expiry":"Sep 16, 2016"},{"cid":"446084522487295","name":"","s":"TSLA160916C00170000","e":"OPRA","p":"27.00","cs":"chb","c":"0.00","cp":"0.00","b":"30.05","a":"32.10","oi":"12","vol":"-","strike":"170.00","expiry":"Sep 16, 2016"},{"cid":"367689129200491","name":"","s":"TSLA160916C00175000","e":"OPRA","p":"36.20","cs":"chb","c":"0.00","cp":"0.00","b":"25.15","a":"27.25","oi":"52","vol":"-","strike":"175.00","expiry":"Sep 16, 2016"},{"cid":"129646035642327","name":"","s":"TSLA160916C00180000","e":"OPRA","p":"17.20","cs":"chb","c":"0.00","cp":"0.00","b":"20.85","a":"22.05","oi":"91","vol":"-","strike":"180.00","expiry":"Sep 16, 2016"},{"cid":"733865215077307","name":"","s":"TSLA160916C00185000","e":"OPRA","p":"16.00","cs":"chg","c":"+2.50","cp":"18.52","b":"16.45","a":"17.40","oi":"34","vol":"33","strike":"185.00","expiry":"Sep 16, 2016"},{"cid":"568231138866100","name":"","s":"TSLA160916C00190000","e":"OPRA","p":"13.50","cs":"chg","c":"+3.45","cp":"34.33","b":"12.20","a":"12.65","oi":"855","vol":"8","strike":"190.00","expiry":"Sep 16, 2016"},{"cid":"427189940524630","name":"","s":"TSLA160916C00195000","e":"OPRA","p":"8.40","cs":"chg","c":"+1.75","cp":"26.32","b":"8.50","a":"8.85","oi":"1102","vol":"21","strike":"195.00","expiry":"Sep 16, 2016"},{"cid":"1082141592051119","name":"","s":"TSLA160916C00200000","e":"OPRA","p":"5.55","cs":"chg","c":"+1.40","cp":"33.73","b":"5.40","a":"5.65","oi":"1990","vol":"364","strike":"200.00","expiry":"Sep 16, 2016"},{"cid":"230121558689237","name":"","s":"TSLA160916C00205000","e":"OPRA","p":"3.47","cs":"chg","c":"+1.12","cp":"47.66","b":"3.15","a":"3.35","oi":"1324","vol":"455","strike":"205.00","expiry":"Sep 16, 2016"},{"cid":"894705236612609","name":"","s":"TSLA160916C00210000","e":"OPRA","p":"1.94","cs":"chg","c":"+0.65","cp":"50.39","b":"1.72","a":"1.80","oi":"3867","vol":"681","strike":"210.00","expiry":"Sep 16, 2016"},{"cid":"40801284708400","name":"","s":"TSLA160916C00215000","e":"OPRA","p":"0.94","cs":"chg","c":"+0.23","cp":"32.39","b":"0.90","a":"0.96","oi":"2711","vol":"375","strike":"215.00","expiry":"Sep 16, 2016"},{"cid":"529249705826744","name":"","s":"TSLA160916C00220000","e":"OPRA","p":"0.49","cs":"chg","c":"+0.10","cp":"25.64","b":"0.47","a":"0.52","oi":"4705","vol":"173","strike":"220.00","expiry":"Sep 16, 2016"},{"cid":"579788906485048","name":"","s":"TSLA160916C00225000","e":"OPRA","p":"0.31","cs":"chg","c":"+0.06","cp":"24.00","b":"0.26","a":"0.31","oi":"3102","vol":"105","strike":"225.00","expiry":"Sep 16, 2016"},{"cid":"695785114703989","name":"","s":"TSLA160916C00230000","e":"OPRA","p":"0.18","cs":"chg","c":"+0.02","cp":"12.50","b":"0.15","a":"0.21","oi":"4291","vol":"142","strike":"230.00","expiry":"Sep 16, 2016"},{"cid":"294592085765220","name":"","s":"TSLA160916C00235000","e":"OPRA","p":"0.13","cs":"chg","c":"+0.04","cp":"44.44","b":"0.09","a":"0.15","oi":"2715","vol":"40","strike":"235.00","expiry":"Sep 16, 2016"},{"cid":"614241625252","name":"","s":"TSLA160916C00240000","e":"OPRA","p":"0.05","cs":"chr","c":"-0.06","cp":"-54.55","b":"0.05","a":"0.12","oi":"4062","vol":"11","strike":"240.00","expiry":"Sep 16, 2016"},{"cid":"35412973124711","name":"","s":"TSLA160916C00245000","e":"OPRA","p":"0.15","cs":"chg","c":"+0.09","cp":"150.00","b":"0.05","a":"0.15","oi":"1359","vol":"8","strike":"245.00","expiry":"Sep 16, 2016"},{"cid":"523084247103734","name":"","s":"TSLA160916C00250000","e":"OPRA","p":"0.05","cs":"chg","c":"+0.02","cp":"66.67","b":"0.05","a":"0.10","oi":"12156","vol":"6","strike":"250.00","expiry":"Sep 16, 2016"},{"cid":"386089758942689","name":"","s":"TSLA160916C00255000","e":"OPRA","p":"0.14","cs":"chg","c":"+0.10","cp":"250.00","b":"0.01","a":"0.14","oi":"4097","vol":"1","strike":"255.00","expiry":"Sep 16, 2016"},{"cid":"342874639110958","name":"","s":"TSLA160916C00260000","e":"OPRA","p":"0.05","cs":"chg","c":"+0.02","cp":"66.67","b":"0.01","a":"0.06","oi":"5511","vol":"13","strike":"260.00","expiry":"Sep 16, 2016"},{"cid":"951449640597665","name":"","s":"TSLA160916C00265000","e":"OPRA","p":"0.03","cs":"chr","c":"-0.06","cp":"-66.67","b":"0.01","a":"0.04","oi":"693","vol":"4","strike":"265.00","expiry":"Sep 16, 2016"},{"cid":"109380551285141","name":"","s":"TSLA160916C00270000","e":"OPRA","p":"0.01","cs":"chr","c":"-0.04","cp":"-80.00","b":"-","a":"0.03","oi":"1893","vol":"10","strike":"270.00","expiry":"Sep 16, 2016"},{"cid":"663774558210813","name":"","s":"TSLA160916C00275000","e":"OPRA","p":"0.05","cs":"chb","c":"0.00","cp":"0.00","b":"0.01","a":"0.03","oi":"1124","vol":"-","strike":"275.00","expiry":"Sep 16, 2016"},{"cid":"112668851965328","name":"","s":"TSLA160916C00280000","e":"OPRA","p":"0.02","cs":"chb","c":"0.00","cp":"0.00","b":"0.01","a":"0.03","oi":"9380","vol":"-","strike":"280.00","expiry":"Sep 16, 2016"},{"cid":"23495629926976","name":"","s":"TSLA160916C00285000","e":"OPRA","p":"0.04","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"616","vol":"-","strike":"285.00","expiry":"Sep 16, 2016"},{"cid":"1004365825285358","name":"","s":"TSLA160916C00290000","e":"OPRA","p":"0.03","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.20","oi":"2332","vol":"-","strike":"290.00","expiry":"Sep 16, 2016"},{"cid":"330197077576914","name":"","s":"TSLA160916C00295000","e":"OPRA","p":"0.10","cs":"chb","c":"0.00","cp":"0.00","b":"0.01","a":"0.03","oi":"271","vol":"-","strike":"295.00","expiry":"Sep 16, 2016"},{"cid":"1015720399686345","name":"","s":"TSLA160916C00300000","e":"OPRA","p":"0.01","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"2034","vol":"2","strike":"300.00","expiry":"Sep 16, 2016"},{"cid":"371787846867782","name":"","s":"TSLA160916C00305000","e":"OPRA","p":"0.07","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.13","oi":"191","vol":"-","strike":"305.00","expiry":"Sep 16, 2016"},{"cid":"794756977768746","name":"","s":"TSLA160916C00310000","e":"OPRA","p":"0.06","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.13","oi":"341","vol":"-","strike":"310.00","expiry":"Sep 16, 2016"},{"cid":"589274365602892","name":"","s":"TSLA160916C00315000","e":"OPRA","p":"0.01","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.13","oi":"85","vol":"-","strike":"315.00","expiry":"Sep 16, 2016"},{"cid":"958135383206851","name":"","s":"TSLA160916C00320000","e":"OPRA","p":"0.02","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"449","vol":"-","strike":"320.00","expiry":"Sep 16, 2016"},{"cid":"957518746875187","name":"","s":"TSLA160916C00325000","e":"OPRA","p":"0.05","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"174","vol":"-","strike":"325.00","expiry":"Sep 16, 2016"},{"cid":"947410564957569","name":"","s":"TSLA160916C00330000","e":"OPRA","p":"0.05","cs":"chb","c":"0.00","cp":"0.00","b":"0.01","a":"0.02","oi":"254","vol":"-","strike":"330.00","expiry":"Sep 16, 2016"},{"cid":"936370081872094","name":"","s":"TSLA160916C00335000","e":"OPRA","p":"0.08","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"121","vol":"-","strike":"335.00","expiry":"Sep 16, 2016"},{"cid":"869235801270819","name":"","s":"TSLA160916C00340000","e":"OPRA","p":"0.05","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"122","vol":"-","strike":"340.00","expiry":"Sep 16, 2016"},{"cid":"784091407817438","name":"","s":"TSLA160916C00345000","e":"OPRA","p":"0.79","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"38","vol":"-","strike":"345.00","expiry":"Sep 16, 2016"},{"cid":"85239239120130","name":"","s":"TSLA160916C00350000","e":"OPRA","p":"0.05","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"454","vol":"-","strike":"350.00","expiry":"Sep 16, 2016"},{"cid":"211447090706369","name":"","s":"TSLA160916C00355000","e":"OPRA","p":"1.93","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"20","vol":"-","strike":"355.00","expiry":"Sep 16, 2016"},{"cid":"351823136572506","name":"","s":"TSLA160916C00360000","e":"OPRA","p":"0.55","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"64","vol":"-","strike":"360.00","expiry":"Sep 16, 2016"},{"cid":"804800293852884","name":"","s":"TSLA160916C00365000","e":"OPRA","p":"1.35","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"118","vol":"-","strike":"365.00","expiry":"Sep 16, 2016"},{"cid":"774749443516921","name":"","s":"TSLA160916C00370000","e":"OPRA","p":"0.23","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"23","vol":"-","strike":"370.00","expiry":"Sep 16, 2016"},{"cid":"62924785666214","name":"","s":"TSLA160916C00375000","e":"OPRA","p":"0.17","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"168","vol":"-","strike":"375.00","expiry":"Sep 16, 2016"},{"cid":"762305391919801","name":"","s":"TSLA160916C00380000","e":"OPRA","p":"0.10","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.13","oi":"89","vol":"-","strike":"380.00","expiry":"Sep 16, 2016"},{"cid":"793017123886757","name":"","s":"TSLA160916C00385000","e":"OPRA","p":"1.45","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"228","vol":"-","strike":"385.00","expiry":"Sep 16, 2016"},{"cid":"826948232988990","name":"","s":"TSLA160916C00390000","e":"OPRA","p":"0.45","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"41","vol":"-","strike":"390.00","expiry":"Sep 16, 2016"},{"cid":"598383802441737","name":"","s":"TSLA160916C00395000","e":"OPRA","p":"0.24","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"20","vol":"-","strike":"395.00","expiry":"Sep 16, 2016"},{"cid":"983900197677305","name":"","s":"TSLA160916C00400000","e":"OPRA","p":"0.02","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"278","vol":"-","strike":"400.00","expiry":"Sep 16, 2016"},{"cid":"322652828621972","name":"","s":"TSLA160916C00410000","e":"OPRA","p":"0.15","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"25","vol":"-","strike":"410.00","expiry":"Sep 16, 2016"},{"cid":"55290337064305","name":"","s":"TSLA160916C00420000","e":"OPRA","p":"0.49","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"48","vol":"-","strike":"420.00","expiry":"Sep 16, 2016"},{"cid":"406767026062965","name":"","s":"TSLA160916C00430000","e":"OPRA","p":"-","c":"-","b":"-","a":"0.03","oi":"0","vol":"-","strike":"430.00","expiry":"Sep 16, 2016"},{"cid":"806365700330173","name":"","s":"TSLA160916C00440000","e":"OPRA","p":"0.84","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"60","vol":"-","strike":"440.00","expiry":"Sep 16, 2016"},{"cid":"225372731645320","name":"","s":"TSLA160916C00450000","e":"OPRA","p":"0.06","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"41","vol":"-","strike":"450.00","expiry":"Sep 16, 2016"},{"cid":"341884545155871","name":"","s":"TSLA160916C00460000","e":"OPRA","p":"0.94","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"29","vol":"-","strike":"460.00","expiry":"Sep 16, 2016"},{"cid":"760487192324210","name":"","s":"TSLA160916C00470000","e":"OPRA","p":"0.20","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"27","vol":"-","strike":"470.00","expiry":"Sep 16, 2016"},{"cid":"211838278250894","name":"","s":"TSLA160916C00480000","e":"OPRA","p":"0.10","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"89","vol":"-","strike":"480.00","expiry":"Sep 16, 2016"}]


However, I'm getting the error message (from the
print
):

JsError(List(((5)/cp,List(ValidationError(List(error.path.missing),WrappedArray()))), ((5)/cs,List(ValidationError(List(error.path.missing),WrappedArray()))), ((6)/cp,List(ValidationError(List(error.path.missing),WrappedArray()))), ((6)/cs,List(ValidationError(List(error.path.missing),WrappedArray()))), ((11)/cp,List(ValidationError(List(error.path.missing),WrappedArray()))), ((11)/cs,List(ValidationError(List(error.path.missing),WrappedArray()))), ((12)/cp,List(ValidationError(List(error.path.missing),WrappedArray()))), ((12)/cs,List(ValidationError(List(error.path.missing),WrappedArray()))), ((14)/cp,List(ValidationError(List(error.path.missing),WrappedArray()))), ((14)/cs,List(ValidationError(List(error.path.missing),WrappedArray()))), ((15)/cp,List(ValidationError(List(error.path.missing),WrappedArray()))), ((15)/cs,List(ValidationError(List(error.path.missing),WrappedArray()))), ((16)/cp,List(ValidationError(List(error.path.missing),WrappedArray()))), ((16)/cs,List(ValidationError(List(error.path.missing),WrappedArray()))), ((82)/cp,List(ValidationError(List(error.path.missing),WrappedArray()))), ((82)/cs,List(ValidationError(List(error.path.missing),WrappedArray())))))


What am I missing?

EDIT:

Apparently the "cp" field is missing in 8/88 instances. As I am only interested in the fields "p" and "strike". I change my question to:

How can read only those two fields (p and strike)? Ignoring the rest.

Answer

If you only interested in "p" and "strike" fields, you can use the following code:

case class OptionEntry(p: String,
                   strike: String)

val optionEntries = Json.parse(jsonString)

implicit val optionEntryReads: Reads[OptionEntry] = (
  (JsPath \ "p").read[String] and
    (JsPath \ "strike").read[String]
)(OptionEntry.apply _)

println(optionEntries.validate[List[OptionEntry]])

So you don't have to read all fields. But if you want to keep fields and you know that "cp" field is missing sometimes, you can set it to Option by following code:

case class OptionEntry(cid: String,
                       name: String,
                       s: String,
                       e: String,
                       p: String,
                       cs: String,
                       c: String,
                       cp: Option[String],
                       b: String,
                       a: String,
                       oi: String,
                       vol: String,
                       strike: String,
                       expiry: String)   

val optionEntries = Json.parse(jsonString)

implicit val optionEntryReads: Reads[OptionEntry] = (
  (JsPath \ "cid").read[String] and
    (JsPath \ "name").read[String] and
    (JsPath \ "s").read[String] and
    (JsPath \ "e").read[String] and
    (JsPath \ "p").read[String] and
    (JsPath \ "cs").read[String] and
    (JsPath \ "c").read[String] and
    (JsPath \ "cp").readNullable[String] and
    (JsPath \ "b").read[String] and
    (JsPath \ "a").read[String] and
    (JsPath \ "oi").read[String] and
    (JsPath \ "vol").read[String] and
    (JsPath \ "strike").read[String] and
    (JsPath \ "expiry").read[String]
)(OptionEntry.apply _)

println(optionEntries.validate[List[OptionEntry]])