title: How to create a JSON object in Scala?
body: <p>First, I searched a lot on Google and StackOverflow for questions like that, but I didn't find any useful answers (to my big surprise).</p>
  <p>I saw something about <a href="https://www.playframework.com/documentation/2.0/ScalaJson" rel="nofollow noreferrer">Play Framework</a>, <a href="https://stackoverflow.com/questions/7976643/how-to-create-json-array-in-java">how to create JSON array in Java</a> and <a href="https://stackoverflow.com/questions/18983185/how-to-create-correct-jsonarray-in-java-using-jsonobject">how to create JSON objects in Java</a>, but I don't want to use Play Framework and I don't know if the creation of JSON objects differ from Scala to Java.</p>
  <p>Following is the JSON I want to create. Later I'll convert the object into a string to send it via a POST request (through an API call).</p>
  <pre><code>{
      &quot;start_relative&quot;: {
          &quot;value&quot;: &quot;5&quot;,
          &quot;unit&quot;: &quot;years&quot;
      },
      &quot;metrics&quot;: [
          {
          &quot;name&quot;: &quot;DP_391366&quot; # S-Temperature - Celsius
          },
          {
              &quot;name&quot;: &quot;DP_812682&quot; # Sensor-A4 Luminosity
          }
      ]
  }
  </code></pre>
  <p>How can I do something like that in Scala?</p>