<commit_before>package lila.common

import play.api.libs.json._

object PimpedJson extends PimpedJson

trait PimpedJson {

  implicit final class LilaPimpedJsObject(js: JsObject) {

    def str(key: String): Option[String] =
      (js \ key).asOpt[String]

    def int(key: String): Option[Int] =
      (js \ key).asOpt[Int]

    def long(key: String): Option[Long] =
      (js \ key).asOpt[Long]

    def boolean(key: String): Option[Boolean] =
      (js \ key).asOpt[Boolean]

    def obj(key: String): Option[JsObject] =
      (js \ key).asOpt[JsObject]

    def arr(key: String): Option[JsArray] =
      (js \ key).asOpt[JsArray]

    def arrAs[A](key: String)(as: JsValue => Option[A]): Option[List[A]] =
      arr(key) map { _.value.toList map as flatten }

    def ints(key: String): Option[List[Int]] = arrAs(key)(_.asOpt[Int])

    def get[A: Reads](key: String): Option[A] =
      (js \ key).asOpt[A]

    def noNull = JsObject {
      js.fields collect {
        case (key, value) if value != JsNull => key -> value
      }
    }
  }

  implicit final class LilaPimpedJsValue(js: JsValue) {

    def str(key: String): Option[String] =
      js.asOpt[JsObject] flatMap { obj =>
        (obj \ key).asOpt[String]
      }
<commit_msg>make PimpedJson an AnyVal<commit_after>package lila.common

import play.api.libs.json._

object PimpedJson {

  implicit final class LilaPimpedJsObject(val js: JsObject) extends AnyVal {

    def str(key: String): Option[String] =
      (js \ key).asOpt[String]

    def int(key: String): Option[Int] =
      (js \ key).asOpt[Int]

    def long(key: String): Option[Long] =
      (js \ key).asOpt[Long]

    def boolean(key: String): Option[Boolean] =
      (js \ key).asOpt[Boolean]

    def obj(key: String): Option[JsObject] =
      (js \ key).asOpt[JsObject]

    def arr(key: String): Option[JsArray] =
      (js \ key).asOpt[JsArray]

    def arrAs[A](key: String)(as: JsValue => Option[A]): Option[List[A]] =
      arr(key) map { _.value.toList map as flatten }

    def ints(key: String): Option[List[Int]] = arrAs(key)(_.asOpt[Int])

    def get[A: Reads](key: String): Option[A] =
      (js \ key).asOpt[A]

    def noNull = JsObject {
      js.fields collect {
        case (key, value) if value != JsNull => key -> value
      }
    }
  }

  implicit final class LilaPimpedJsValue(val js: JsValue) extends AnyVal {

    def str(key: String): Option[String] =
      js.asOpt[JsObject] flatMap { obj =>
        (obj \ key).asOpt[String]
      }

{'fraction_non_alphanumeric': 0.14977973568281938, 'fraction_numerical': 0.0, 'mean_word_length': 2.837173579109063, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4810600', 'n_tokens_mistral': 912, 'n_tokens_neox': 886, 'n_words': 209}